-
Notifications
You must be signed in to change notification settings - Fork 0
/
exip.py
31 lines (26 loc) · 858 Bytes
/
exip.py
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
31
import urllib, json
import smtplib
email = "ian@EMAIL_ADDRESS.com"
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login( email , "CHANGE_ME_PASSWORD")
print "Logging to server..."
data = json.loads(urllib.urlopen("http://ip.jsontest.com/").read())
ip = data["ip"]
print "Current IP: " + ip
file_loc = "C:\Users\ischwartz\ownCloud\exip\exip-data.txt" # LINUX SERVER= /saved/scripts/exip
print "Locating file..."
print "Comparing IPs..."
exipR = open(file_loc,"r")
exipRead = exipR.read()
exipR.close()
if ip != exipRead:
print "Same IP, no change recorded"
else:
print "Changed IP: " + ip
exipO = open(file_loc,"w")
exipO.write(ip)
exipO.close()
msg = "\n Changed ip: " + ip # The \n separates the message from the headers
server.sendmail( email, email , msg)