Python Network Programming
by Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
How it works...
This recipe uses the sniff() and wrpacp() utility functions of the Scapy library to capture all the network packets and dump them onto a file. After capturing a packet via sniff(), the write_cap() function is called on that packet. Some global variables are used to work on packets one after another. For example, packets are stored in a pkts[] list and packet and variable counts are used. When the value of the count is 3, the pkts list is dumped onto a file named pcap1.pcap, the count variable is reset so that we can continue capturing another three packets and dumped onto pcap2.pcap, and so on.
In the test_dump_file() function, assume the presence of the first dump file, pcap1.dump, in the working directory. Now, sniff()
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.
Read now
Unlock full access