根据ip138插口完成ip或域名注册查询
插口详细地址:https://m.ip138.com/
python 编码完成
import urllib.request
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.request.urlopen('http://wap.ip138.com/ip.asp?ip=' ip)
fip = uip.read()
rip = re.compile("<br/><b>查看結果:(.*)</b><br/>")
result = rip.findall(fip)
print("%s\t %s" % (ip, result[0]))
def DO(domain):
url = urllib.request.urlopen('http://wap.ip138.com/ip.asp?ip=' domain)
f = url.read().decode('utf-8')
r = re.compile('<br/><b>查看結果:(.*)</b><br/>')
result = r.findall(f)
#print type(result)
for i in result:
print("%s %s %s" % (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('(\w \.)?(\w )(\.\D ){1,2}',INPUT) :
DOMAIN=INPUT
DO(DOMAIN)
else:
print("键入的IP地址和域名格式不对!")
else:
if ISIP(INPUT) :
IPADDRESS=INPUT
URL(IPADDRESS)
else:
print("IP 详细地址不合理合法,请再次键入!")