Skip to content

Instantly share code, notes, and snippets.

@suziewong
Last active March 27, 2020 10:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save suziewong/7909364 to your computer and use it in GitHub Desktop.
Save suziewong/7909364 to your computer and use it in GitHub Desktop.
根据域名查IP,物理地址
#!//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