-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamicipnotif.py
More file actions
30 lines (26 loc) · 842 Bytes
/
Copy pathdynamicipnotif.py
File metadata and controls
30 lines (26 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import urllib.request
#Below code is used to get the previous IP from a text file and the new IP address
#It then stores them as variables
path = "/home/pi/programs/testprogs/ipaddress.txt"
openfile = open(path,"r")
read_ip = openfile.readline()
openfile.close()
try:
external_ip = urllib.request.urlopen("https://ident.me").read().decode("utf8")
except:
external_ip = read_ip
if external_ip == read_ip:
exit()
else:
openfile = open(path,"w")
openfile.write(external_ip)
openfile.close()
import http.client, urllib
conn = http.client.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.parse.urlencode({
"token":[TOKEN HERE],
"user":[TOKEN HERE],
"message":"IP Address has updated to: "+external_ip,
}), {"Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()