Initial release

This commit is contained in:
2004-01-10 22:30:44 +00:00
commit 025a4a79e8

51
dnsupdate.py Normal file
View File

@@ -0,0 +1,51 @@
import dns.query
import dns.tsigkeyring
import dns.update
import re
import string
import sys
domain = "lubcke.se"
keyname = "lubcke.se."
keysecret = "ZGhNJ05b8ThmHOXhJvkvMw=="
# Updates a dns-record
def update():
# Get command line args
if len(sys.argv) != 3:
print "Usage: dnsupdate.py hostname 192.168.0.1"
return
hostname = sys.argv[1]
ipaddress = sys.argv[2]
# Sanity check incoming data
hostname = string.replace(hostname, "."+domain, '')
if not re.search('^[12]?[0-9]?[0-9](\.[12]?[0-9]?[0-9]){3}$', ipaddress):
print "Invalid ip address '%s'" % ipaddress
return
# The name of the key and the secret
keyring = dns.tsigkeyring.from_text({
keyname: keysecret
})
# dns.update.Update(name of domain, keyring, keyname)
update = dns.update.Update(domain, keyring=keyring, keyname=keyname)
# update.replace(hostname, ttl, record-type, new ip)
update.replace(hostname, 60, 'a', ipaddress)
# doit, servername
response = dns.query.tcp(update, 'nic.wahlberg.se')
# Verify response
if response.rcode() == 0:
print "Host '%s.%s' has been added with ip address %s" % (hostname, domain, ipaddress)
else:
print "An error has occurred, the server returned:\n%s" % response
if __name__=="__main__":
update()