[2016-01-18][python][查询IP所在地]

[2016-01-18][python][查询IP所在地]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from urllib import request
import json
def GetIPCity(ip,city):
    with request.urlopen("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip="+ip) as f:
           data = f.read()
    st = json.loads(data.decode('utf-8'))
    city[0= st['country']
    city[1= st['province']
    city[2= st['city']
 
 
city = ["","",""]
ip = "183.62.57.244"
GetIPCity(ip,city)
print(city)


来自为知笔记(Wiz)


posted on 2016-01-18 10:52  红洋  阅读(124)  评论(0)    收藏  举报

导航