forked from rocfy/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_ip138.py
executable file
·45 lines (38 loc) · 1.19 KB
/
check_ip138.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/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 地址不合法,请重新输入!"