Filtering UDP packets

In the following example, we see how we define a function that will be executed every time a packet of type UDP is obtained when making a DNS request:

scapy> a = sniff(filter="UDP and port 53",count=100,prn=count_dns_request)

This function can be defined from the command line in this way. First we define a global variable called DNS_QUERIES, and when scapy finds a packet with the UDP protocol and port 53, it will call this function to increment this variable, which indicates there has been a DNS request in the communications:

>>> DNS_QUERIES=0
>>> def count_dns_request(package):
>>> global DNS_QUERIES
>>> if DNSQR in package:
>>> DNS_QUERIES +=1
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.186