Skip to content

Instantly share code, notes, and snippets.

@quinncnl
Created June 23, 2013 00:55
Show Gist options
  • Save quinncnl/5843291 to your computer and use it in GitHub Desktop.
Save quinncnl/5843291 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import urllib.request
import re, time, os
def getIP():
try:
with urllib.request.urlopen('http://myip.com.tw/') as f:
a = f.read().decode('utf-8')
except:
print ("network error")
return lastIP
return re.search("(\d+\.\d+\.\d+\.\d+)", a).group(1)
def updateIP():
print(os.system("curl http://usn:[email protected]/ph/update"))
lastIP = getIP();
print(lastIP)
while True:
time.sleep(30)
IP = getIP();
if IP != lastIP:
lastIP = IP
updateIP()
print("updated")
else:
print("same")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment