ddns.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. #
  3. # Use a TSIG-signed DDNS update to update our hostname-to-address
  4. # mapping.
  5. #
  6. # usage: ddns.py <ip-address>
  7. #
  8. # On linux systems, you can automatically update your DNS any time an
  9. # interface comes up by adding an ifup-local script that invokes this
  10. # python code.
  11. #
  12. # E.g. on my systems I have this
  13. #
  14. # #!/bin/sh
  15. #
  16. # DEVICE=$1
  17. #
  18. # if [ "X${DEVICE}" == "Xeth0" ]; then
  19. # IPADDR=`LANG= LC_ALL= ifconfig ${DEVICE} | grep 'inet addr' |
  20. # awk -F: '{ print $2 } ' | awk '{ print $1 }'`
  21. # /usr/local/sbin/ddns.py $IPADDR
  22. # fi
  23. #
  24. # in /etc/ifup-local.
  25. #
  26. import sys
  27. import dns.update
  28. import dns.query
  29. import dns.tsigkeyring
  30. #
  31. # Replace the keyname and secret with appropriate values for your
  32. # configuration.
  33. #
  34. keyring = dns.tsigkeyring.from_text({
  35. 'keyname.' : 'NjHwPsMKjdN++dOfE5iAiQ=='
  36. })
  37. #
  38. # Replace "example." with your domain, and "host" with your hostname.
  39. #
  40. update = dns.update.Update('example.', keyring=keyring)
  41. update.replace('host', 300, 'A', sys.argv[1])
  42. #
  43. # Replace "10.0.0.1" with the IP address of your master server.
  44. #
  45. response = dns.query.tcp(update, '10.0.0.1', timeout=10)