Skip to content

Instantly share code, notes, and snippets.

@thepacketgeek
Last active July 7, 2023 11:43
Show Gist options
  • Save thepacketgeek/6928674 to your computer and use it in GitHub Desktop.
Save thepacketgeek/6928674 to your computer and use it in GitHub Desktop.
Simple DNS Query with Scapy
from scapy.all import *
answer = sr1(IP(dst="8.8.8.8")/UDP(dport=53)/DNS(rd=1,qd=DNSQR(qname="www.thepacketgeek.com")),verbose=0)
print answer[DNS].summary()
@setrus
Copy link

setrus commented Feb 17, 2021

I suggest getting some DNS bins online to track your requests. In this case I used requestbin.net
Here is an example that works

>>> ans = sr1(IP(dst="8.8.8.8")/UDP(sport=RandShort(), dport=53)/DNS(rd=1,qd=DNSQR(qname="7a645c14a2eaac.d.requestbin.net",qtype="A")))
Begin emission:
Finished to send 1 packets.
*
Received 1 packets, got 1 answers, remaining 0 packets
>>> **ans.an.rdata**
'127.0.0.1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment