git clone https://github.com/hongwenjun/ip.git
pip3 install Flask ipip-ipdb
cd ip
wget https://cdn.jsdelivr.net/npm/qqwry.ipdb/qqwry.ipdb
flask run --host=0.0.0.0
- 如果要挂载
/app
目录,宿主机先准备好文件
docker run -d -p 80:5000 --restart=always --name ip hongwenjun/ip
Pytyhon 使用百度地图API 进行 IP普通定位和地图显示
演示网址: https://www.262235.xyz/ip/maps/
- https://market.aliyun.com/products/57002002/cmapi00035184.html
app.py
中请更换你自己的 API
def ip2gdgps(ip):
url = 'http://ips.market.alicloudapi.com/iplocaltion?ip=' + ip
headers = {"Authorization":"APPCODE <<<IP定位APPCODE>>>" ,"Content-Type":"application/json; charset=utf-8" }
try:
r = requests.get(url=url , headers=headers)
data = r.json()
except :
return
# print(data)
if data['code'] != 100:
return (116.39564504, 39.92998578 , data['code']) # 查不到返回 北京 x,y
elif data['message'] == "success":
x = data['result']['lng']
y = data['result']['lat']
return (x, y, data['code'], data)