-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathddns.py
35 lines (30 loc) · 983 Bytes
/
ddns.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
import sys
import time
from util import *
import config
UPDATE_INTERVAL = 600
public_ip = 'N/A'
def get_public_ip():
return get('checkip.amazonaws.com', '/').read().decode().rstrip()
def update_succesfull(res):
return res.status == 200 and '<ErrCount>0</ErrCount>' in res.read().decode()
def update_ddns():
params = [
'?host=' + config.read('host'),
'&domain=' + config.read('domain'),
'&password=' + config.read('ddns_password')
]
res = get('dynamicdns.park-your-domain.com', '/update' + ''.join(params))
if update_succesfull(res):
print('Succesfully updated DNS.')
return True
else:
print('DNS update failed.', file=sys.stderr)
return False
while True:
current_ip = get_public_ip()
if public_ip != current_ip:
print('Public IP Changed from ' + public_ip + ' to ' + current_ip + '.')
if update_ddns():
public_ip = current_ip
time.sleep(UPDATE_INTERVAL)