Created
October 19, 2014 06:23
-
-
Save nroberson/b9fb64cd0969f9a17998 to your computer and use it in GitHub Desktop.
Print your public ip geo info periodically
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 json | |
import urllib2 | |
import time | |
GET_IP_URI = 'https://freegeoip.net/json' | |
SLEEP_TIME_S = 25 * 60 | |
def get_geo_json(): | |
content = urllib2.urlopen(GET_IP_URI).read() | |
if len(content) > 0: | |
return content | |
else: | |
return None | |
if __name__ == '__main__': | |
while(1): | |
geo_json = get_geo_json() | |
if geo_json is None: | |
print "Failed to get response" | |
else: | |
jdata = json.loads(geo_json) | |
for k, v in jdata.iteritems(): | |
print "%s: %s" % (k,v) | |
print "\n\n" | |
time.sleep(SLEEP_TIME_S) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment