From e0b7e598e0c940c1294d066af4fe037a490b4df1 Mon Sep 17 00:00:00 2001 From: Gitouche Date: Mon, 26 Sep 2022 22:08:43 +0200 Subject: [PATCH] add multidomain support - broken ipv6 --- src/example.config.py | 6 ++++- src/gandi-live-dns.py | 54 +++++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/example.config.py b/src/example.config.py index 7ac37fc..fb03a6b 100644 --- a/src/example.config.py +++ b/src/example.config.py @@ -24,7 +24,11 @@ api_endpoint = 'https://dns.api.gandi.net/api/v5' domain = 'mydomain.tld' #enter all subdomains to be updated, subdomains must already exist to be updated -subdomains = ["subdomain1", "subdomain2", "subdomain3"] +#your domain and subdomains to be updated, subdomains must already exist to be updated +dnsentries = { + "mydomain.tld": ["subdomain1", "subdomain2"], + "myotherdomain.tld": ["subdomain3"], +} #300 seconds = 5 minutes ttl = '300' diff --git a/src/gandi-live-dns.py b/src/gandi-live-dns.py index c367b31..c63c888 100755 --- a/src/gandi-live-dns.py +++ b/src/gandi-live-dns.py @@ -125,37 +125,41 @@ def main(force_update, verbosity, repeat): if repeat and verbose: print(f'repeat turned on, will repeat every {repeat} seconds') - #get zone ID from Account - uuid = get_uuid() + for key, value in config.dnsentries.items(): + config.domain = key + config.subdomains = value - #compare dynIP and DNS IP - dynIP = get_dynip(config.ifconfig, verbose) + #get zone ID from Account + uuid = get_uuid() - if check_is_ipv6(dynIP, verbose): - subdomains = config.subdomains6 - is_ipv6 = True - print('Detected ipv6') - else: - print('Detected ipv4') - is_ipv6 = False - subdomains = config.subdomains + #compare dynIP and DNS IP + dynIP = get_dynip(config.ifconfig, verbose) - dnsIP = get_dnsip(uuid, is_ipv6, verbose) - - if force_update: - print ('Going to update/create the DNS Records for the subdomains') - for sub in subdomains: - update_records(uuid, dynIP, sub, is_ipv6, verbose) - else: - if verbose: - print(f'dynIP: {dynIP}') - print(f'dnsIP: {dnsIP}') - if dynIP == dnsIP: - print ('IP Address Match - no further action') + if check_is_ipv6(dynIP, verbose): + subdomains = config.subdomains6 + is_ipv6 = True + print('Detected ipv6') else: - print (f'IP Address Mismatch - going to update the DNS Records for the subdomains with new IP {dynIP}') + print('Detected ipv4') + is_ipv6 = False + subdomains = config.subdomains + + dnsIP = get_dnsip(uuid, is_ipv6, verbose) + + if force_update: + print ('Going to update/create the DNS Records for the subdomains') for sub in subdomains: update_records(uuid, dynIP, sub, is_ipv6, verbose) + else: + if verbose: + print(f'dynIP: {dynIP}') + print(f'dnsIP: {dnsIP}') + if dynIP == dnsIP: + print ('IP Address Match - no further action') + else: + print (f'IP Address Mismatch - going to update the DNS Records for the subdomains with new IP {dynIP}') + for sub in subdomains: + update_records(uuid, dynIP, sub, is_ipv6, verbose) if repeat: if verbosity: print(f'Repeating in {repeat} seconds')