-
Notifications
You must be signed in to change notification settings - Fork 1
/
dnsSniffer.py
26 lines (17 loc) · 905 Bytes
/
dnsSniffer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/python
from scapy.all import DNSQR, DNSRR, UDP, IP, DNS, sniff
from datetime import datetime
INTERFACE = "eth0" # change to your sniffing interface
# number of sniffed queries, don't forget that for every query there is a response. Uncomment if you want to specify the number of DNS packets
# NUMBER_QUERIES = 10
def grep_DNS_queries(packet):
packet_time = packet.sprintf('%sent.time%')
try:
if DNSQR in packet and packet.dport == 53:
print packet[DNS].summary() + '\n[' + packet[IP].src + '] -> [' + packet[IP].dst + '] at [' + packet_time + ']'
elif DNSRR in packet and packet.sport == 53:
print packet[DNS].summary() + '\n['+ packet[IP].src + '] -> [' + packet[IP].dst + '] at [' + packet_time + ']'
except:
pass
# sniffs the packets
packets = sniff(iface = INTERFACE, filter = "udp and port 53", store = 0, prn = grep_DNS_queries)#, count = NUMBER_QUERIES)