Skip to content

Instantly share code, notes, and snippets.

@nroberson
Created October 19, 2014 06:23
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 nroberson/b9fb64cd0969f9a17998 to your computer and use it in GitHub Desktop.
Save nroberson/b9fb64cd0969f9a17998 to your computer and use it in GitHub Desktop.
Print your public ip geo info periodically
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