Compare commits

...

4 commits

Author SHA1 Message Date
Gitouche 1f59fcf8db Update example.config.py 2022-09-23 17:27:45 +02:00
Gitouche 3832ec2709 Update ifconfig.co example endpoint 2021-10-27 22:32:13 +02:00
Gitouche cd1def40e1 manage multiple domains 2021-01-09 16:02:14 +01:00
Guigui Benmaurice 8c1ae5abdd Update to python3 2019-12-28 22:01:48 +01:00
2 changed files with 37 additions and 41 deletions

View file

@ -20,11 +20,11 @@ https://dns.api.gandi.net/api/v5/
'''
api_endpoint = 'https://dns.api.gandi.net/api/v5'
#your domain with the subdomains in the zone file/UUID
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'
@ -36,7 +36,7 @@ run your own external IP provider:
+ <?php $ip = $_SERVER['REMOTE_ADDR']; ?>
<?php print $ip; ?>
e.g.
+ https://ifconfig.co/ip
+ https://ifconfig.co
+ http://ifconfig.me/ip
+ http://whatismyip.akamai.com/
+ http://ipinfo.io/ip

View file

@ -22,8 +22,8 @@ def get_dynip(ifconfig_provider):
similar to curl ifconfig.me/ip, see example.config.py for details to ifconfig providers
'''
r = requests.get(ifconfig_provider)
print 'Checking dynamic IP: ' , r._content.strip('\n')
return r.content.strip('\n')
print('Checking dynamic IP: ' , r.text.strip('\n'))
return r.text.strip('\n')
def get_uuid():
'''
@ -38,8 +38,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 +56,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')
return 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').decode().strip('\n'))
return json_object['rrset_values'][0].encode('ascii','ignore').decode().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,11 +80,11 @@ 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()
@ -92,8 +92,11 @@ def update_records(uuid, dynIP, subdomain):
def main(force_update, verbosity):
if verbosity:
print "verbosity turned on - not implemented by now"
print("verbosity turned on - not implemented by now")
for key, value in config.dnsentries.items():
config.domain = key
config.subdomains = value
#get zone ID from Account
uuid = get_uuid()
@ -103,14 +106,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)
@ -120,11 +123,4 @@ if __name__ == "__main__":
parser.add_argument('-f', '--force', help="force an update/create", action="store_true")
args = parser.parse_args()
main(args.force, args.verbose)