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() is used with an offline parameter, which captured packets from the file instead of network. Here, the packets are decoded one after another using the hexdump() function. The contents of the packets are then printed on the screen.

..................Content has been hidden....................

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