File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/python
2+ #coding:utf-8
3+
4+ import urllib .request
5+ import re
6+ import sys
7+
8+ def ISIP (s ):
9+ return len ([i for i in s .split ('.' ) if (0 <= int (i )<= 255 )])== 4
10+
11+ def URL (ip ):
12+ uip = urllib .request .urlopen ('http://wap.ip138.com/ip.asp?ip=' + ip )
13+ fip = uip .read ()
14+ rip = re .compile ("<br/><b>查询结果:(.*)</b><br/>" )
15+ result = rip .findall (fip )
16+ print ("%s\t %s" % (ip , result [0 ]))
17+
18+
19+ def DO (domain ):
20+ url = urllib .request .urlopen ('http://wap.ip138.com/ip.asp?ip=' + domain )
21+ f = url .read ().decode ('utf-8' )
22+ r = re .compile ('<br/><b>查询结果:(.*)</b><br/>' )
23+ result = r .findall (f )
24+ #print type(result)
25+ for i in result :
26+ print ("%s %s %s" % (domain , i [0 ], i [1 ]))
27+
28+ if __name__ == "__main__" :
29+ if len (sys .argv ) < 2 :
30+ print ("请输入IP地址或者域名 (例如:192.168.1.1 / www.baidu.com)" )
31+ sys .exit ()
32+ INPUT = sys .argv [1 ]
33+ if not re .findall ('(\d{1,3}\.){3}\d{1,3}' ,INPUT ):
34+ if re .findall ('(\w+\.)?(\w+)(\.\D+){1,2}' ,INPUT ) :
35+ DOMAIN = INPUT
36+ DO (DOMAIN )
37+ else :
38+ print ("输入的IP地址和域名格式不对!" )
39+ else :
40+ if ISIP (INPUT ) :
41+ IPADDRESS = INPUT
42+ URL (IPADDRESS )
43+ else :
44+ print ("IP 地址不合法,请重新输入!" )
You can’t perform that action at this time.
0 commit comments