Skip to content

Instantly share code, notes, and snippets.

@thearn
Last active December 16, 2015 11:59
Show Gist options
  • Save thearn/5431198 to your computer and use it in GitHub Desktop.
Save thearn/5431198 to your computer and use it in GitHub Desktop.
A python code to determine a computer's external IP address, which is then written to a text file. Run from a dropbox folder (or something similar), this provides a very simple way to determine your home's dynamic external IP address remotely.
import urllib
import re
import time
import datetime
def get_ip():
group = re.compile(u'(?P<ip>\d+\.\d+\.\d+\.\d+)').search(
urllib.URLopener().open('http://jsonip.com/').read()).groupdict()
return group['ip']
if __name__ == '__main__':
ip = get_ip()
print "ip:", ip, "..."
file = open("ip.txt", "w")
file.write(ip + "\n")
file.write(str(datetime.datetime.now()))
file.close()
time.sleep(60 * 15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment