clean ipv6 support
This commit is contained in:
parent
e0b7e598e0
commit
fcb18989b9
|
@ -26,10 +26,16 @@ 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
|
||||||
#your domain and subdomains to be updated, subdomains must already exist to be updated
|
#your domain and subdomains to be updated, subdomains must already exist to be updated
|
||||||
dnsentries = {
|
dnsentries = {
|
||||||
"mydomain.tld": ["subdomain1", "subdomain2"],
|
"mydomain.tld": {
|
||||||
"myotherdomain.tld": ["subdomain3"],
|
"ipv4": ["subdomain1", "subdomain2"],
|
||||||
|
"ipv6": ["subdomain3v6"],
|
||||||
|
},
|
||||||
|
"myotherdomain.tld": {
|
||||||
|
"ipv4": ["subdomain4"],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#300 seconds = 5 minutes
|
#300 seconds = 5 minutes
|
||||||
ttl = '300'
|
ttl = '300'
|
||||||
|
|
||||||
|
|
|
@ -65,11 +65,10 @@ def get_dnsip(uuid, is_ipv6=False, verbose=False):
|
||||||
'''
|
'''
|
||||||
if is_ipv6:
|
if is_ipv6:
|
||||||
record_type = '/AAAA'
|
record_type = '/AAAA'
|
||||||
subdomain = config.subdomains6[0]
|
|
||||||
else:
|
else:
|
||||||
record_type = '/A'
|
record_type = '/A'
|
||||||
subdomain = config.subdomains[0]
|
|
||||||
|
|
||||||
|
subdomain = config.subdomains[0]
|
||||||
url = config.api_endpoint+ '/zones/' + uuid + '/records/' + subdomain + record_type
|
url = config.api_endpoint+ '/zones/' + uuid + '/records/' + subdomain + record_type
|
||||||
headers = {'X-Api-Key':config.api_secret}
|
headers = {'X-Api-Key':config.api_secret}
|
||||||
u = requests.get(url, headers=headers)
|
u = requests.get(url, headers=headers)
|
||||||
|
@ -125,41 +124,43 @@ 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')
|
||||||
|
|
||||||
for key, value in config.dnsentries.items():
|
for domain, content in config.dnsentries.items():
|
||||||
config.domain = key
|
config.domain = domain
|
||||||
config.subdomains = value
|
for key, value in content.items():
|
||||||
|
afi = key
|
||||||
|
config.subdomains = value
|
||||||
|
|
||||||
#get zone ID from Account
|
#get zone ID from Account
|
||||||
uuid = get_uuid()
|
uuid = get_uuid()
|
||||||
|
|
||||||
#compare dynIP and DNS IP
|
#compare dynIP and DNS IP
|
||||||
dynIP = get_dynip(config.ifconfig, verbose)
|
dynIP = get_dynip(config.ifconfig[afi], verbose)
|
||||||
|
|
||||||
|
if check_is_ipv6(dynIP, verbose):
|
||||||
|
is_ipv6 = True
|
||||||
|
print('Detected ipv6')
|
||||||
|
else:
|
||||||
|
print('Detected ipv4')
|
||||||
|
is_ipv6 = False
|
||||||
|
|
||||||
|
dnsIP = get_dnsip(uuid, is_ipv6, verbose)
|
||||||
|
|
||||||
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
|
subdomains = config.subdomains
|
||||||
|
|
||||||
dnsIP = get_dnsip(uuid, is_ipv6, verbose)
|
if force_update:
|
||||||
|
print ('Going to update/create the DNS Records for the subdomains')
|
||||||
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:
|
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')
|
||||||
|
|
Loading…
Reference in a new issue