-
-
Save thepacketgeek/6928674 to your computer and use it in GitHub Desktop.
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() |
Please help, when I try
sr1(IP(dst="8.8.8.8")/UDP(dport=53)/DNS(rd=1,qd=DNSQR(qname="google.com")),verbose=0)
It hangs, but when I use
sr1(IP(dst="192.168.1.1")/UDP(dport=53)/DNS(rd=1,qd=DNSQR(qname="google.com")),verbose=0)
, everything works.
192.168.1.1 is my wifi gateway, I don't know how to connect to 8.8.8.8
Edited:
Problem is solved by adding sport
.
sr1(IP(dst="8.8.8.8")/UDP(sport=RandShort(), dport=53)/DNS(rd=1,qd=DNSQR(qname="google.com")),verbose=0)
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'
@MarryamZulfiqar Scapy has a REPL. Just type scapy to your console (needs a superuser/admin account) and start forging packets and requests. Here's the documentation: https://scapy.readthedocs.io/en/latest/usage.html#simple-one-liners