简体   繁体   中英

dnspython: How can I get response as bytes

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM