Last active
March 27, 2020 10:42
-
-
Save suziewong/7909364 to your computer and use it in GitHub Desktop.
根据域名查IP,物理地址
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!//usr/bin/python | |
# encoding=utf-8 | |
import sys | |
import socket | |
import urllib2 | |
import json | |
import re | |
if __name__ =="__main__": | |
if len(sys.argv) == 2: | |
domain = sys.argv[1] | |
# 获取域名的IP地址 | |
try: | |
domain = re.search('(http|https)://(.*)/',domain).group(2) | |
except: | |
print "Wrong domain OR IP" | |
sys.exit(2) | |
result = socket.getaddrinfo(domain, None) | |
ip = result[0][4][0] | |
url = "http://ip.taobao.com/service/getIpInfo.php?ip="+ip | |
res = urllib2.urlopen(url) | |
data = res.read() | |
objs = json.loads(data) | |
if re.findall(r'\d+.\d+.\d+.\d+', domain): | |
domain = '' | |
if objs['data']: | |
print domain,ip,objs['data']['country'],objs['data']['region'],objs['data']['city'],objs['data']['isp'] | |
else: | |
print domain,ip | |
else: | |
print "Usage():" | |
print " ip.py www.taobao.com|http://www.taobao.com/|42.1.1.1" | |
sys.exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment