-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pack a DNS request message #40
Comments
Following shows a simple demo which build QNAME for domain name google = asyncdns.build_address("google.com")
print(binascii.hexlify(google)) It prints (just as what we wish: each label consists of a length octet followed by that number of octets.)
|
As #39 has showed, the dns request to google.com is Then we can build the request as follows:
It prints as what we analysis from the data package which is captured from wireshark when
|
Function build_address use
Python2>>> type(chr(34))
<type 'str'>
>>> type(chr(34)) is bytes
True
>>> import binascii
>>> binascii.hexlify(chr(34))
'22' Python3>>> type(chr(34))
<class 'str'>
>>> binascii.hexlify(chr(34))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required, not 'str'
>>> bytes([34])
b'"'
>>> binascii.hexlify(bytes([34]))
b'22' |
As issue #38 mentioned, the top level format of message is divided into 5 sections (some of which are empty in certain cases) shown below:
So, we need to fill these five section to make a DNS request message.
Header
The format string pack the DNS request header section as followers:
Details:
In
asyncdns.build_request
, there are following snippet:Format string
!HBBHHHH
specify that the byte order is network(= big-endian), and:Question
The question section is used to carry the "question" in most queries, i.e., the parameters that define what is being asked. The section contains QDCOUNT (usually 1) entries, each of the following format:
The following snippet packs the QTYPE and QCLASS para in question section.
QNAME is created by the following snippet:
Ref
#37 Struct: working with binary data
#38 Data format of message used in DNS
#39 View DNS data datagram via wireshark
The text was updated successfully, but these errors were encountered: