So what I'm trying to do is extract the domain name, e.g. youtube.com, from a dns query using python.
This is the code that I am using to generate my query data. :
import socket
port = 53
ip = '127.0.0.1'
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((ip, port))
while 1:
data, addr = sock.recvfrom(512)
print(data)
The query data returned by the code is a hex string:
e2 58 01 00 00 01
00 00 00 00 00 01 07 79 6f 75 74 75 62 65 03 63
6f 6d 00 00 1c 00 01 00 00 29 02 00 00 00 00 00
00 00
And I would like to extract the domain name:
07 79 6f 75 74 75 62 65 03 63
6f 6d 00
Maybe something similar to this answer but for the query not the response
I am using python 3.8