Last active
December 16, 2015 11:59
-
-
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.
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 | |
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