Skip to content

Instantly share code, notes, and snippets.

@quinncnl
Last active December 18, 2015 20:49
Show Gist options
  • Save quinncnl/5843102 to your computer and use it in GitHub Desktop.
Save quinncnl/5843102 to your computer and use it in GitHub Desktop.
#!/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