Created
June 23, 2013 00:55
-
-
Save quinncnl/5843291 to your computer and use it in GitHub Desktop.
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
#!/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