您的位置:首页 > 其它

判断IP地址是否为国内

2017-04-19 00:00 106 查看
import urllib
import urllib2

f = open("ipLibrary.txt", "r")
f_new = open('log.txt','a')
while True:
line = f.readline()
if line:
pass    # do something here
line=line.strip()
if line.find('|CN|ipv4|') > 0:
#pass
f_new.write(str(line.split('|')[3] +"\n"))
print line.split('|')[2], line.split('|')[3]
else:
pass

else:

break
f.close()

#url = 'http://freeapi.ipip.net/'
url = 'http://freeapi.ipip.net/1.0.1.0'
req = urllib2.Request(url)
#print req
res_data = urllib2.urlopen(req)
res = res_data.read()
print res
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: