-
-
Save ammarx/d4155116fe141686c0bca77d8c0aebb8 to your computer and use it in GitHub Desktop.
get_ip_info.py
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
import urllib, json, sys | |
# output here | |
try: | |
url = "http://ip-api.com/json/" + str(sys.argv[1]) | |
response = urllib.urlopen(url) | |
data = json.loads(response.read()) | |
print "Argument: " + str(sys.argv[1]) | |
try: | |
print "City: " + data["city"] | |
except: | |
print "City: N/A" | |
try: | |
print "Country: " + data["country"] | |
except: | |
print "Country: N/A" | |
try: | |
print "Country Code: " + data["countryCode"] | |
except: | |
print "Country Code: N/A" | |
try: | |
print "ISP: " + data["isp"] | |
except: | |
print "ISP: N/A" | |
try: | |
print "Lat: " + str(data["lat"]) | |
except: | |
print "Lat: N/A" | |
try: | |
print "Lon: " + str(data["lon"]) | |
except: | |
print "Lon: N/A" | |
try: | |
print "Query: " + data["query"] | |
except: | |
print "Query: N/A" | |
except Exception: | |
print "Connection error or invalid argument!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment