Skip to content

Instantly share code, notes, and snippets.

@apermuy
Created September 17, 2023 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apermuy/35517ee31ca9c94130d2c1f5717c2c9a to your computer and use it in GitHub Desktop.
Save apermuy/35517ee31ca9c94130d2c1f5717c2c9a to your computer and use it in GitHub Desktop.
Homemade recipe to update an A DNS record using the Dinahosting API
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