-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip.py
59 lines (46 loc) · 1.17 KB
/
ip.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python3
import smtplib
import subprocess
import os
import time
LAST_IP = None
def write_updated_ip(ip):
file = open("ip", "w")
file.write(ip)
file.close()
os.system("git pull")
os.system("git add ip")
os.system("git commit -m 'script updating ip'")
os.system("git push")
def write_no_update_log():
file = open("log", "w")
file.write("\n" + time.strftime("%a, %d %b %Y %H:%M:%S"))
file.close()
os.system("git pull")
os.system("git add log")
os.system("git commit -m 'script updating log'")
os.system("git push")
def check_ip():
global LAST_IP
command = ["curl", "icanhazip.com"]
external_ip = subprocess.Popen(command, stdout=subprocess.PIPE ).communicate()[0]
external_ip = external_ip.decode("ASCII")
if LAST_IP != external_ip:
print("IP updated from", LAST_IP, "to", external_ip)
write_updated_ip(external_ip)
LAST_IP = external_ip
else:
print("checked IP, no change")
write_no_update_log()
def load_past_ip():
global LAST_IP
file = open("ip", "r")
past_ip = file.read(64)
if past_ip:
print("Found past IP", past_ip)
LAST_IP = past_ip
load_past_ip()
check_ip()
while(True):
time.sleep(12 * 60 * 60) # 12 hours in seconds
check_ip()