add multidomain support - broken ipv6

This commit is contained in:
Gitouche 2022-09-26 22:08:43 +02:00
parent d504a6a177
commit e0b7e598e0
2 changed files with 34 additions and 26 deletions

View file

@ -24,7 +24,11 @@ api_endpoint = 'https://dns.api.gandi.net/api/v5'
domain = 'mydomain.tld' domain = 'mydomain.tld'
#enter all subdomains to be updated, subdomains must already exist to be updated #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 #300 seconds = 5 minutes
ttl = '300' ttl = '300'

View file

@ -125,37 +125,41 @@ def main(force_update, verbosity, repeat):
if repeat and verbose: if repeat and verbose:
print(f'repeat turned on, will repeat every {repeat} seconds') print(f'repeat turned on, will repeat every {repeat} seconds')
#get zone ID from Account for key, value in config.dnsentries.items():
uuid = get_uuid() config.domain = key
config.subdomains = value
#compare dynIP and DNS IP #get zone ID from Account
dynIP = get_dynip(config.ifconfig, verbose) uuid = get_uuid()
if check_is_ipv6(dynIP, verbose): #compare dynIP and DNS IP
subdomains = config.subdomains6 dynIP = get_dynip(config.ifconfig, verbose)
is_ipv6 = True
print('Detected ipv6')
else:
print('Detected ipv4')
is_ipv6 = False
subdomains = config.subdomains
dnsIP = get_dnsip(uuid, is_ipv6, verbose) if check_is_ipv6(dynIP, verbose):
subdomains = config.subdomains6
if force_update: is_ipv6 = True
print ('Going to update/create the DNS Records for the subdomains') print('Detected ipv6')
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: 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: for sub in subdomains:
update_records(uuid, dynIP, sub, is_ipv6, verbose) 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 repeat:
if verbosity: if verbosity:
print(f'Repeating in {repeat} seconds') print(f'Repeating in {repeat} seconds')