Skip to Content
Mastering Python for Networking and Security
book

Mastering Python for Networking and Security

by José Manuel Ortega
September 2018
Intermediate to advanced
426 pages
10h 46m
English
Packt Publishing
Content preview from Mastering Python for Networking and Security

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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Python for Networking and Security - Second Edition

Mastering Python for Networking and Security - Second Edition

José Manuel Ortega
Python for Cybersecurity

Python for Cybersecurity

Howard E. Poston, III

Publisher Resources

ISBN: 9781788992510Supplemental Content