From 2cf1af686b8fd8f09b29d4299ae043cf3d4b1bf3 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 21 Jul 2023 20:18:06 -0400 Subject: [PATCH] python3, static ip --- src/gandi-live-dns.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/gandi-live-dns.py b/src/gandi-live-dns.py index 55e5757..a3d7a07 100755 --- a/src/gandi-live-dns.py +++ b/src/gandi-live-dns.py @@ -21,8 +21,11 @@ def get_dynip(ifconfig_provider): ''' find out own IPv4 at home <-- this is the dynamic IP which changes more or less frequently similar to curl ifconfig.me/ip, see example.config.py for details to ifconfig providers ''' + if config.static_ip != "": + return config.static_ip.strip('\n') + r = requests.get(ifconfig_provider) - print 'Checking dynamic IP: ' , r._content.strip('\n') + print('Checking dynamic IP: ' , r._content.strip('\n')) return r.content.strip('\n') def get_uuid(): @@ -38,8 +41,8 @@ def get_uuid(): if u.status_code == 200: return json_object['zone_uuid'] else: - print 'Error: HTTP Status Code ', u.status_code, 'when trying to get Zone UUID' - print json_object['message'] + print('Error: HTTP Status Code ', u.status_code, 'when trying to get Zone UUID') + print(json_object['message']) exit() def get_dnsip(uuid): @@ -56,11 +59,11 @@ def get_dnsip(uuid): u = requests.get(url, headers=headers) if u.status_code == 200: json_object = json.loads(u._content) - print 'Checking IP from DNS Record' , config.subdomains[0], ':', json_object['rrset_values'][0].encode('ascii','ignore').strip('\n') + print('Checking IP from DNS Record' , config.subdomains[0], ':', json_object['rrset_values'][0].encode('ascii','ignore').strip('\n')) return json_object['rrset_values'][0].encode('ascii','ignore').strip('\n') else: - print 'Error: HTTP Status Code ', u.status_code, 'when trying to get IP from subdomain', config.subdomains[0] - print json_object['message'] + print('Error: HTTP Status Code ', u.status_code, 'when trying to get IP from subdomain', config.subdomains[0]) + print(json_object['message']) exit() def update_records(uuid, dynIP, subdomain): @@ -80,19 +83,18 @@ def update_records(uuid, dynIP, subdomain): json_object = json.loads(u._content) if u.status_code == 201: - print 'Status Code:', u.status_code, ',', json_object['message'], ', IP updated for', subdomain + print('Status Code:', u.status_code, ',', json_object['message'], ', IP updated for', subdomain) return True else: - print 'Error: HTTP Status Code ', u.status_code, 'when trying to update IP from subdomain', subdomain - print json_object['message'] + print('Error: HTTP Status Code ', u.status_code, 'when trying to update IP from subdomain', subdomain) + print(json_object['message']) exit() def main(force_update, verbosity): - if verbosity: - print "verbosity turned on - not implemented by now" + print("verbosity turned on - not implemented by now") #get zone ID from Account @@ -103,14 +105,14 @@ def main(force_update, verbosity): dnsIP = get_dnsip(uuid) if force_update: - print "Going to update/create the DNS Records for the subdomains" + print("Going to update/create the DNS Records for the subdomains") for sub in config.subdomains: update_records(uuid, dynIP, sub) else: if dynIP == dnsIP: - print "IP Address Match - no further action" + print("IP Address Match - no further action") else: - print "IP Address Mismatch - going to update the DNS Records for the subdomains with new IP", dynIP + print("IP Address Mismatch - going to update the DNS Records for the subdomains with new IP", dynIP) for sub in config.subdomains: update_records(uuid, dynIP, sub)