Is there an easy way to access the values of A or CNAME or NS records from a python module? I’d like to do something with the IP address in the A record but after digging down into qstate.return_msg.rep.rrsets[i].entry.data.rr_data[j], I can’t see how to turn that into an IP address (for RR_TYPE_A) or hostname (for RR_TYPE_CNAME).
Is there an easy way to access the values of A or CNAME or NS
records from a python module? I'd like to do something with the IP
address in the A record but after digging down into
qstate.return_msg.rep.rrsets[i].entry.data.rr_data[j], I can't see
how to turn that into an IP address (for RR_TYPE_A) or hostname
(for RR_TYPE_CNAME).
Any help would be much appreciated.
You know that the IP address in the RR TYPE A is the plain 4 octets
that make up the IPv4 address? You can convert it to string with
various system routines. The CNAME data is a hostname in DNS
wireformat. That you can also read in, but you need DNS routines.
(the formats are defined in RFC1034).
ldns, has a python library API. That can read DNS records, and then
you can manipulate them, and convert them. That also works for other
record types (DNSKEY and DS and so on). http://nlnetlabs.nl/projects/ldns