dnspython: How can I get response as bytes

783 Views Asked by At

What I am trying to do is make a dns query using the dnspython library and get the response in the dns wire format or a string of bytes. Right not the dns.resolver.resolve() method is returning a <class 'dns.resolver.Answer'>

Is there a way I can get the dns response in the wire format or convert my dns.resolver.Answer type to wire format?

1

There are 1 best solutions below

0
On BEST ANSWER

You can convert the message to the compressed DNS wire format by using something like

my_answer.response.to_wire()

if that's what you need.

From the docs:

response: A dns.message.Message, the response message.

and also:

to_wire(origin=None, max_size=0, multi=False, tsig_ctx=None, **kw)

Return a string containing the message in DNS compressed wire format.