Verbatim large column https://www.dazhuanlan.com/2019/08/26/5d633ce17b786/
A few days ago in a follow-up query to provide ip internal project, the primary database used ipip, the query page while providing some of the results provided by third parties to collect some api
Taobao
Recommended: 5 stars
url: "http://ip.taobao.com/service/getIpInfo.php?ip="+ip
Back json format data code
field of 0 indicates a successful query, geographic location data comprises mainly 'country', 'area', 'region', 'city', 'isp', the request frequency is limited and should be no greater than 10ps
Routine:python
url = "http://ip.taobao.com/service/getIpInfo.php?ip="+ip
try:
r = requests.get(url, timeout=5)
except Exception, e:
result = {
"error": 1,
"msg": '请求失败'
}
return result
if r.status_code == requests.codes.ok:
data = r.json()
if data['code'] == 0:
t = data.get('data')
msg = [t.get('country',''), t.get('area',''), t.get('region',''), t.get('city',''), t.get('isp','')]
result = {
"error": data['code'],
"msg": ' '.join(msg),
"thirdpart": '淘宝'
}
Sina
Recommended degree: 4 stars
url: "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip="+ip
Returns a string containing javascript statements in jquery environment, can be directly used getScript () function to get and assignment. The main data includes geographic 'country', 'province', 'city', 'isp'
Routine: python
url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip="+ip
try:
r = requests.get(url, timeout=5)
except Exception, e:
result = {
"error": 1,
"msg": '请求失败'
}
return result
if r.status_code == requests.codes.ok:
data = r.text
content = data.split('=')[-1].strip()[:-1]
try:
t = simplejson.loads(content)
except Exception, e:
result = {
"error": 1,
"msg": '请求失败'
}
return result
msg = [t.get('country',''), t.get('province',''), t.get('city',''), t.get('isp','')]
result = {
"error": 0,
"msg": ' '.join(msg),
"thirdpart": '新浪'
}
Pacific IP address database (pconline)
Recommended degree: 3 stars
url: "http://whois.pconline.com.cn/ip.jsp?ip="+ip
Direct return location string, of course, can return different data formats by calling the different interfaces, see details here
Routine:python
url = "http://whois.pconline.com.cn/ip.jsp?ip="+ip
try:
r = requests.get(url, timeout=5)
except Exception, e:
result = {
"error": 1,
"msg": '请求失败'
}
return result
if r.status_code == requests.codes.ok:
data = r.text
result = {
"error": 0,
"msg": data,
"thirdpart": 'pconline'
}
ip138
Recommended degree: 4 stars
url: "http://test.ip138.com/query/?ip="+ip
It returns a string containing the same geographic location information
Routine:python
url = "http://test.ip138.com/query/?ip="+ip
try:
r = requests.get(url, timeout=5)
except Exception, e:
result = {
"error": 1,
"msg": '请求失败'
}
return result
if r.status_code == requests.codes.ok:
data = r.json()
if data.get("ret") == "ok":
msg = data.get("data")
result = {
"error": 0,
"msg": ' '.join(msg),
"thirdpart": 'ip138'
}
GeoIp
url: "http://geoip.nekudo.com/api/%s/zh" % ip
GeoIp have an offline version of the database can be downloaded, call the method provides multiple languages, including a python, look here if you do not use the offline version, this site provides api, return json format data routines:python
url = "http://geoip.nekudo.com/api/%s/zh" % ip
try:
r = requests.get(url, timeout=5)
except Exception, e:
result = {
"error": 1,
"msg": '请求失败'
}
return result
if r.status_code == requests.codes.ok:
data = r.json()
msg = [data.get("country",[]).get("name") or '', data.get("city") or '']
result = {
"error": 0,
"msg": ' '.join(msg),
"thirdpart": 'GeoIp'
}