#!/usr/bin/python #coding:utf-8 import urllib import re import sys def ISIP(s): return len([i for i in s.split('.') if (0<= int(i)<= 255)])== 4 def URL(ip): uip=urllib.urlopen('http://wap.ip138.com/ip.asp?ip=%s'%ip) fip=uip.read() rip=re.compile(r"<br/><b>查询结果:(.*)</b><br/>") result=rip.findall(fip) print "%s\t %s" %(ip,result[0]) def DO(domain): url=urllib.urlopen('http://wap.ip138.com/ip.asp?ip=%s'%domain) f=url.read() r=re.compile(r'> (.*)<br/><b>查询结果:(.*)</b><br/>') result=r.findall(f) #print type(result) for i in result: print "%s\t %s\t %s\t" %(domain,i[0],i[1]) if __name__ == "__main__": if len(sys.argv) < 2: print "请输入IP地址或者域名 (例如:192.168.1.1 / www.baidu.com)" sys.exit() INPUT=sys.argv[1] if not re.findall('(\d{1,3}\.){3}\d{1,3}',INPUT): if re.findall(r'(\w+\.)?(\w+)(\.\D+){1,2}',INPUT) : DOMAIN=INPUT DO(DOMAIN) else: print "输入的IP地址和域名格式不对!" else: if ISIP(INPUT) : IPADDRESS=INPUT URL(IPADDRESS) else: print "IP 地址不合法,请重新输入!"
python学习-使用ip138查询ip地址归属地
原创
©著作权归作者所有:来自51CTO博客作者羊草的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
IP138查询工具
IP138查询工具
IP138查询工具 -
IP地址归属地批量查询python代码
上传包含ip地址的csv或者excel文件,将会遍历查询每一个ip的归属地信息
IP json 文件名 python 归属地查询 -
IP地址查询区域名或IP归属地
IP地址查询
IP 开发者社区 API