|
|
|
@ -15,6 +15,7 @@ load_dotenv(verbose=True, dotenv_path=env_path)
|
|
|
|
|
|
|
|
|
|
PDNS_API_BASE = os.getenv("PDNS_API_BASE")
|
|
|
|
|
PDNS_TOKEN = os.getenv("PDNS_TOKEN")
|
|
|
|
|
TMPFILE = '/tmp/lastIP'
|
|
|
|
|
|
|
|
|
|
def pprint(text):
|
|
|
|
|
print (json.dumps(text, sort_keys=True, indent=4, separators=(',', ': ')))
|
|
|
|
@ -29,7 +30,7 @@ def set_record(zone, name, type, record):
|
|
|
|
|
{
|
|
|
|
|
'name': name,
|
|
|
|
|
'type': type,
|
|
|
|
|
'ttl': 1,
|
|
|
|
|
'ttl': 30,
|
|
|
|
|
'changetype': "REPLACE",
|
|
|
|
|
'records': [ record ]
|
|
|
|
|
}
|
|
|
|
@ -42,17 +43,33 @@ def set_record(zone, name, type, record):
|
|
|
|
|
print (p.text)
|
|
|
|
|
print (p.status_code)
|
|
|
|
|
|
|
|
|
|
record = {
|
|
|
|
|
'disabled': False,
|
|
|
|
|
'content': get_ip()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
|
record = {
|
|
|
|
|
'disabled': False,
|
|
|
|
|
'content': get_ip()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
|
|
|
|
|
|
if os.path.exists(TMPFILE):
|
|
|
|
|
with open(TMPFILE) as file:
|
|
|
|
|
try:
|
|
|
|
|
lastIP=file.read()
|
|
|
|
|
except:
|
|
|
|
|
printf('error reading ' + TMPFILE)
|
|
|
|
|
else:
|
|
|
|
|
lastIP = ''
|
|
|
|
|
|
|
|
|
|
currentIP = get_ip()
|
|
|
|
|
|
|
|
|
|
if lastIP == currentIP:
|
|
|
|
|
print ('IP has not changed since last call')
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
record = {
|
|
|
|
|
'disabled': False,
|
|
|
|
|
'content': currentIP
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_record (sys.argv[1], sys.argv[2]+'.', 'A', record)
|
|
|
|
|
|
|
|
|
|
with open(TMPFILE, 'w') as file:
|
|
|
|
|
file.write(currentIP)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
print('Updates ip record of NAME in ZONE to current IP from ipinfo.io\n\nUsage:\n' + sys.argv[0] + ' ZONE NAME')
|
|
|
|
|
print('Updates IP record of NAME in ZONE to current IP from ipinfo.io\n\nUsage:\n' + sys.argv[0] + ' ZONE NAME')
|
|
|
|
|