Skip to content

Instantly share code, notes, and snippets.

@mozillazg
Last active December 29, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mozillazg/7701657 to your computer and use it in GitHub Desktop.
Save mozillazg/7701657 to your computer and use it in GitHub Desktop.
get ip info
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import sys
import urllib
if __name__ == '__main__':
args = sys.argv
if len(args) < 2:
ip = 'myip'
else:
ip = args[1]
url = 'http://ip.taobao.com/service/getIpInfo.php?ip={0}'.format(ip)
response = urllib.urlopen(url)
body = json.loads(response.read())
code = body['code']
if code == 0:
data = body['data']
for key, value in data.items():
print(u'{0:<12}: {1}'.format(key, value))
else:
print('Get ip info fail!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment