Python Network Programming
by Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
How it works...
This recipe reads a saved pcap file, pcap1.pcap, from the disk using the PcapReader() function of Scapy that returns an iterator of packets. The command-line arguments are parsed if they are supplied. Otherwise, the default value is used as shown in the preceding output.
The command-line arguments and the packet list are passed to the send_packet() function. This function places the new packets in the p_out list and keeps track of the processed packets. In each packet, the payload is modified, thus changing the source and destination IPs. In addition to this, the checksum packet is deleted as it was based on the original IP address.
After processing one of the packets, it is sent over the network immediately. After that, the ...
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