# -*- coding: utf-8 -*-
import urllib2,json
'''
@Time : 2015-01-19
@Author : zilangboya
@Version: 1.0
'''
# 使用sina的公開ip查詢接口,返回ip所屬國家、省、市
# 以及服務商、ip段起始、結尾地址
def ipool(ip):
print "The ip lookup: ",ip
url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='+ip
postdata = urllib2.urlopen(url).read()
josndata = json.loads(postdata) # 返回數據 ---> json格式
country = josndata['country'] # 國家
province = josndata['province'] # 省
city = josndata['city'] # 市
isp = josndata['isp'] # 服務商
start = josndata['start'] # ip段起始
end = josndata['end'] # ip段結尾
print "country :",country
print "province:",province
print "city :",city
print "isp :",isp
print "start :",start
print "end :",end
ip = '202.108.22.5'
ipool(ip)
使用sina公開接口查詢ip地址信息
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.