Examine the resultsΒΆ

This example shows how to go through the obtained results

# MX is a small program that prints out the mx records for a particular domain
import ldns

resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")

pkt = resolver.query("nic.cz", ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
if (pkt) and (pkt.answer()):

    for rr in pkt.answer().rrs():
        if (rr.get_type() != ldns.LDNS_RR_TYPE_MX):

        rdf = rr.owner()
        print rdf," ",rr.ttl()," ",rr.get_class_str()," ",rr.get_type_str()," ",
        print " ".join(str(rdf) for rdf in rr.rdfs())

This snippet of code prints:

nic.cz.   1761   IN   MX   20 mx.cznic.org.
nic.cz.   1761   IN   MX   10 mail.nic.cz.
nic.cz.   1761   IN   MX   15 mail4.nic.cz.

Previous topic

AXFR client with IDN support

Next topic

Read zone file