Last active
December 18, 2015 20:49
-
-
Save quinncnl/5843102 to your computer and use it in GitHub Desktop.
This file contains 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/env python3 | |
import json, sys, socket | |
import urllib.request | |
try: | |
socket.inet_aton(sys.argv[1]) | |
ip=sys.argv[1] | |
except socket.error: | |
ip=socket.gethostbyname(sys.argv[1]) | |
print(ip) | |
with urllib.request.urlopen('http://ip.taobao.com/service/getIpInfo.php?ip='+ip) as f: | |
d = f.read().decode('utf-8') | |
j=json.loads(d) | |
print (j['data']['country'], j['data']['region'], j['data']['city'], j['data']['isp']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment