Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crafting a DNS Query Message in Python

Tags:

python

tcp

I've been using Scapy to craft packets and test my network, but the programmer inside me is itching to know how to do this without Scapy.

For example, how do I craft a DNS Query using sockets (I assume it's sockets that would be used).

Thanks

like image 543
Barry Granger Avatar asked Jul 11 '26 04:07

Barry Granger


1 Answers

To open a UDP socket you'd use:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_UDP

To send use:

query = craft_dns_query() # you do this part s.sendto(query,(socket.inet_aton("8.8.8.8",53))

To receive the response use: response = s.recv(1024)

You'll have to refer to documentation on DNS for actually crafting the messages and handling the responses.

like image 172
chemdt Avatar answered Jul 13 '26 10:07

chemdt