根据第三方 ip 地址库查询归属地:
http://ip.taobao.com/instructions.php
python ipinfo.py
#!/usr/bin/env python
# -- coding: utf-8 --
# --------------------------------------------------
#Author: LJ
#Email: admin@attacker.club
#Site: blog.attacker.club
#Mail: admin@attacker.club
#Date: 2017/9/17
#Description:
# --------------------------------------------------
import urllib2
import json
import sys
#ip = sys.argv[1]
ip = '223.5.5.5'
#查询淘宝ip地址库接口
apiurl = "http://ip.taobao.com/service/getIpInfo.php?ip=%s" % ip
content = urllib2.urlopen(apiurl).read()
data = json.loads(content)['data']
code = json.loads(content)['code']
if code == 0:
print "查询ip地址:%sn来自 %s地区t%st%st%s n" % (data["ip"].encode('utf-8'),\
data["country"].encode('utf-8'),\
data["region"].encode('utf-8'),\
data["city"].encode('utf-8'), \
data["isp"].encode('utf-8')
)
else:
print data.encode('utf-8')