This example shows how to read the content of a zone file
#!/usr/bin/python
import ldns
#Read zone from file
zone = ldns.ldns_zone.new_frm_fp(open("zone.txt","r"), None, 0, ldns.LDNS_RR_CLASS_IN)
print zone
print "SOA:", zone.soa()
for r in zone.rrs().rrs():
print "RR:", r
zone = ldns.ldns_zone()
#print zone
Zone file zone.txt:
$ORIGIN example.
$TTL 600
example. IN SOA example. admin.example. (
2008022501 ; serial
28800 ; refresh (8 hours)
7200 ; retry (2 hours)
604800 ; expire (1 week)
18000 ; minimum (5 hours)
)
@ IN MX 10 mail.example.
@ IN NS ns1
@ IN NS ns2
@ IN A 192.168.1.1