# -*- 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地址信息
最新推荐文章于 2023-03-30 21:29:43 发布