Capturing and replaying packets

Scapy has the ability to listen to the network interface and capture all incoming packets on it. It can write it on a pcap file in the same way that tcpdump works, but Scapy provides additional functions that can read and replay a pcap file, in the network again.

Starting with a simple packet replay, we will instruct Scapy to read a normal pcap file captured from the network (either using tcpdump or Scapy itself) and send it again to the network. This is very useful if we need to test the behavior of the network if a specific traffic pattern travels through it. For example, we may have a network firewall configured to block FTP communication. We can test the functionality of the firewall by hitting it with ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.