Update PTR records

95 views
Skip to first unread message

Jonathan McLoughlin

unread,
Jan 9, 2019, 12:57:43 PM1/9/19
to dnspython-users
I am trying to use dnspython to update a timestamp on a number of PTR records.

An existing script that uses the system nsupdate looks something like this:

server <IP of DNS server>
update add 10.1.1.10.in-addr.arpa. 3600 PTR server1.example.com.
update add 10.1.16.172.in-addr.arpa. 3600 PTR server2.example.com.
send 
update



However from documentation and testing, I believe I need the PTR zone name to use dnspython for this purpose i.e.

record = dns.update.Update(zone='16.172.in-addr.arpa')
record.replace('10.1.16.172.in-addr.arpa.','3600','PTR','server2.example.com.')
dns.query.tcp(record, '<IP of DNS server>')

Is there any option to use dnspython to update PTR records without providing the PTR zone name similar to the nsupdate tool?


Bob Halley

unread,
Jan 9, 2019, 1:26:18 PM1/9/19
to dnspython-users
dnspython provides the dns.resolver.zone_for_name() function to find the zone for a given name.

import dns.resolver
record = dns.update.Update(zone=dns.resolver.zone_for_name('10.1.16.172.in-addr.arpa.'))
# the rest of your update here, same as before

You might also find the dns.reversename module helpful.

>>> import dns.reversename
>>> print(dns.reversename.from_address('172.16.1.10'))
10.1.16.172.in-addr.arpa.

Jonathan McLoughlin

unread,
Jan 10, 2019, 12:16:51 PM1/10/19
to dnspython-users
Thank you!
Works perfectly
Reply all
Reply to author
Forward
0 new messages