Registry / http-networking / scapy
library2.7.0pypypi✓ verified 24d ago

Scapy is a powerful Python-based interactive packet manipulation tool that enables users to forge, decode, send, and sniff network packets. It supports a wide array of protocols and can function as an interactive shell (REPL) or as a library within Python scripts. Scapy runs on Linux, macOS, most Unix-like systems, and Windows (requiring Npcap). The current version is 2.7.0, and it maintains an active release cadence.

pip install scapy
INSTALL
IMPORT
SIG · SCAPY
S
scapy
http-networkingpythonv2.7.0
Install
2.7s avg
Import
3434ms
Disk
36MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 3.550s · 35.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 3.318s · 36MB
36MB installed
● package 36MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

*
from scapy.all import *
from scapy import *
Using `from scapy import *` may not import all necessary modules and functions, especially if there's a name collision with a local 'scapy.py' file. `from scapy.all import *` ensures all Scapy features are loaded.

This quickstart demonstrates how to import Scapy, craft a basic IP/ICMP packet, send it, and process the response. It also includes a commented-out example for sniffing packets. Sending and sniffing raw packets with Scapy typically requires root or administrator privileges. The `sr1` function sends one packet and waits for a single response, while `sniff` can capture multiple packets, using a callback function for processing.

from scapy.all import * # Craft an IP packet with an ICMP payload packet = IP(dst="8.8.8.8")/ICMP() # Send the packet and receive a response # Note: Requires root/admin privileges to send/receive raw packets # Use os.environ.get('SCAPY_IFACE', 'eth0') to specify an interface if needed # For simple testing, can often run as sudo python your_script.py # sr1 sends one packet and waits for one answer # timeout is crucial for non-blocking execution in scripts resp = sr1(packet, timeout=1, verbose=0) if resp: print(f"Received response from: {resp.src}") resp.show() else: print("No response received.") # Example of sniffing packets (run for 2 packets or 5 seconds) # Sniffing often requires elevated privileges def print_packet_summary(pkt): print(pkt.summary()) # sniff(prn=print_packet_summary, count=2, timeout=5) # print("Sniffing complete.")
scapy --version
Debug
Known issues
breakingThe behavior of `StreamSocket` has changed. `TCPSession(app=True)` should no longer be used with `StreamSocket` as custom sessions are now marked unstable. This affects TCP reassembly and other stream-related functionalities.
fix
Review code using `StreamSocket` with `TCPSession(app=True)`. Consider refactoring or consulting Scapy's documentation for updated session management patterns, or using alternative methods for TCP reassembly.
affects: 2.6.x, 2.7.0
breakingThe Scapy CLI configuration file location moved from `~/.scapy_startup.py` to `~/.config/scapy/startup.py` to align with XDG variables. Older configuration files in the old location are no longer functional.
fix
Migrate any custom CLI configuration from `~/.scapy_startup.py` to `~/.config/scapy/startup.py`.
affects: 2.6.x and later
deprecatedUsing the `iface=` argument with Layer 3 functions (`send`, `sr`, `sr1`) is deprecated due to undefined behavior. It remains valid for Layer 2 functions (`sendp`, `srp`, `srp1`).
fix
Avoid using `iface=` with Layer 3 functions. For specific interface binding, configure routing tables or use Layer 2 functions where appropriate. For multicast/link-local addresses, use RFC6874-like scope identifiers (e.g., `dst="ff02::1%eth0"`).
affects: 2.6.x and later
breakingScapy 2.6.x dropped support for Python 2.7. Additionally, Scapy 2.7.0 is announced as the last version to support Python 3.7 and 3.8.
fix
Ensure your environment uses Python 3.9 or newer for future compatibility, especially if relying on Scapy's latest features and maintenance.
affects: 2.6.x (Python 2.7), 2.7.0 (Python 3.7, 3.8)
gotchaScapy often requires root or administrator privileges to send and sniff raw packets, as it interacts directly with network interfaces at a low level.
fix
Run Scapy scripts or the interactive shell with `sudo` on Linux/macOS or as an administrator on Windows. Be mindful of the security implications when running with elevated privileges.
affects: All versions
gotchaScapy might eagerly send real packets to resolve names or perform other network interactions, even when intended for offline analysis. This can lead to unintended network activity.
fix
When performing offline analysis or working in sensitive environments, be aware of Scapy's default behaviors. Explicitly configure `conf.verb = 0` to suppress verbose output and potentially limit active network interactions, and carefully review documentation for functions that may trigger live traffic.
affects: All versions
Errors
Common errors & fixes
NameError: name 'IP' is not defined
Protocol layers and functions from scapy.all are not directly available in the global namespace unless explicitly imported or prefixed.
fix
Use `from scapy.all import *` to import all common names, or refer to them as `scapy.all.IP`.
ModuleNotFoundError: No module named 'scapy'
The Scapy library is not installed in the Python environment or the wrong environment is being used.
fix
Install Scapy using pip: `pip install scapy`
socket.error: [Errno 1] Operation not permitted
Scapy requires root or administrator privileges to create raw sockets for sending and sniffing network packets.
fix
Run your Python script or interpreter with elevated privileges (e.g., `sudo python your_script.py` on Linux/macOS or as Administrator on Windows).
No such device
On Windows, Scapy requires Npcap (or WinPcap) to access network interfaces; if it's not installed or not correctly configured, Scapy cannot find network devices.
fix
Download and install Npcap from the official Npcap website.
Upgrade
Version history
2.7.0latest on PyPI · released Dec 26, 2025
Audit
Dependencies
NpcaprequiredMandatory for Scapy to function on Windows.
libpcaprequiredRequired on Unix-like systems for certain features, particularly BPF filter compilation.
matplotliboptionalOptional, for plotting functionalities.
PyXoptionalOptional, for generating PostScript (psdump) and PDF (pdfdump) diagrams, requires a LaTeX distribution.
GraphvizoptionalOptional, for drawing network graphs and conversations().
ImageMagickoptionalOptional, often used with Graphviz for image processing in graph generation.
VPython-JupyteroptionalOptional, for 3D graphics (trace3D()).
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources