Created
September 17, 2023 14:13
-
-
Save apermuy/35517ee31ca9c94130d2c1f5717c2c9a to your computer and use it in GitHub Desktop.
Homemade recipe to update an A DNS record using the Dinahosting API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import dns.resolver | |
import syslog | |
dinahostingUser = "DINAHOSTING_USERNAME" | |
dinahostingPass = "DINAHOSTING_PASSWORD" | |
urlCheckWan = "https://eth0.me" | |
hostname = "HOSTNAME" | |
domain = "DOMAIN" | |
resolver = dns.resolver.Resolver() | |
resolver.nameservers = ['8.8.8.8'] | |
r = requests.get(urlCheckWan) | |
ipWan = r.text | |
consulta = resolver.resolve(hostname + "." + domain, 'A') | |
for rdata in consulta: | |
ip = (rdata.to_text()) | |
if ipWan.strip() != ip: | |
urlDinahosting = str("https://dinahosting.com/special/api.php?AUTH_USER=" + dinahostingUser +"&AUTH_PWD=" + dinahostingPass + "&domain=" + domain +"&hostname="+ hostname + "&ip=" + ipWan.strip() +"&oldIp=&command=Domain_Zone_UpdateTypeA") | |
updateRecord = requests.post(urlDinahosting) | |
syslog.syslog(syslog.LOG_INFO, "Se ha actualizado el registro DNS A para el dominio: " + hostname + "." + domain + " con el valor " + ipWan.strip()) | |
elif ipWan.strip() == ip: | |
syslog.syslog(syslog.LOG_INFO, "Ejecución script update.py para " + hostname + "." + domain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment