Scapy is a powerful Python-based library designed for packet manipulation, network scanning, discovery, and probing. It allows users to forge, send, capture, and dissect network packets across a wide range of protocols. Unlike many networking tools that operate at a high level of abstraction, Scapy provides low-level access to packet construction, enabling the creation of custom or malformed packets for testing, debugging, and security auditing purposes.
Core Functionality Scapy operates by defining packets as layers of protocols (e.g., Ethernet / IP / TCP / Raw Data). Users can programmatically assemble these layers, modify specific fields (such as TTL, flags, or payload), transmit the packets onto the network, and analyze the responses. It supports both interactive use via a Python shell and scriptable automation for integration into larger tools or workflows.
Key Features
- Packet Crafting: Construct packets from scratch or modify existing captures with granular control over header fields.
- Sending and Receiving: Transmit packets at Layer 2 (raw sockets) or Layer 3 (standard sockets) and match requests with replies using a stimulus/response model.
- Sniffing and Dissection: Capture live traffic or read
pcap/pcapngfiles, automatically dissecting known protocols into manipulable objects. - Protocol Support: Includes built-in support for hundreds of protocols (TCP/IP, DNS, HTTP, DHCP, ARP, ICMP, TLS, 802.11, Bluetooth, etc.) and allows users to define custom protocols.
- Visualization: Generates graphical representations of packet flows, network maps, and protocol hierarchies (e.g., via GraphViz or Matplotlib integration).
History and Development Scapy was originally written by Philippe Biondi and first released in 2005. The original version (often referred to as Scapy v1 or v2.x) was maintained until approximately 2018. Due to a lack of Python 3 support in the original codebase, a community-driven fork named Scapy3k emerged. In 2018, the project was officially rebooted under the name Scapy (versions 2.4.0+), merging the Python 3 compatibility efforts into the main repository hosted on GitHub (secdev/scapy). It is released under the GPLv2 license.
Use Cases
- Network Testing: Verifying firewall rules, IDS/IPS signatures, and protocol implementations.
- Security Auditing: Performing reconnaissance, tracerouting, OS fingerprinting, and vulnerability exploitation (e.g., crafting specific exploits for CVEs).
- Protocol Development: Rapid prototyping and debugging of new network protocols.
- Education: Teaching network internals and protocol analysis due to its interactive Python nature.
Technical Requirements Scapy runs on Linux, macOS, *BSD, and Windows. On Linux and macOS, it typically requires root privileges to open raw sockets for sending/receiving Layer 2 frames. On Windows, it relies on WinPcap or Npcap for packet capture and injection capabilities. It requires Python 3.5 or later.