import ipgetter
import urllib.request
import requests
currentIP= ipgetter.myip()#AutoRemote function to send a notification YOUR_KEY goes heredef sendAR(x):
AR_key='YOUR_KEY'AR_url='http://autoremotejoaomgcd.appspot.com/sendmessage?key='+ AR_key +'&message=IP%20'message= AR_url + x
response= urllib.request.urlopen(message).read() print(x)#check the internet and check if previous file is presenttry:
requests.get('http://www.google.com') print('Internet present')IPfile= open('ipfile.txt', 'r')lastIP= IPfile.read()iflastIP== currentIP:
print('No changes last IP: ' + lastIP + ' current IP: ' + currentIP)else:
with open('ipfile.txt', 'w+') as f:
f.write(currentIP) f.close() sendAR(currentIP) print('IP updated')#handle no file except IOError:
#print(IOError) with open('ipfile.txt', 'w+') as f:
IPfile= ipgetter.myip() f.write(IPfile) f.close() print('created file with current IP') sendAR(currentIP) quit()#Handle no internet except requests.ConnectionError:
quit()