Top Related Projects
fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols
Simple, secure & standards compliant web server for the most demanding of applications
Read-only mirror of Wireshark's Git repository at https://gitlab.com/wireshark/wireshark. ⚠️ GitHub won't let us disable pull requests. ⚠️ THEY WILL BE IGNORED HERE ⚠️ Upload them at GitLab instead.
Quick Overview
Scapy is a powerful interactive packet manipulation program and library written in Python. It can forge or decode packets of a wide number of protocols, send them on the wire, capture them, match requests and replies, and much more. Scapy is designed to allow fast packet prototyping by using default values that work.
Pros
- Highly flexible and customizable for packet manipulation
- Supports a wide range of network protocols
- Can be used as both an interactive tool and a library
- Excellent for network testing, scanning, and penetration testing
Cons
- Steep learning curve for beginners
- Documentation can be overwhelming due to the extensive feature set
- Performance can be slower compared to lower-level tools
- Requires root/administrator privileges for some operations
Code Examples
- Creating and sending a simple ICMP packet:
from scapy.all import *
# Create and send an ICMP ping packet
ping = IP(dst="8.8.8.8")/ICMP()
reply = sr1(ping)
print(reply.summary())
- Sniffing network traffic:
from scapy.all import *
# Sniff 10 packets and print a summary
packets = sniff(count=10)
for packet in packets:
print(packet.summary())
- ARP scanning to discover live hosts on a network:
from scapy.all import *
# Perform ARP scan on local network
ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.0/24"), timeout=2)
for sent, received in ans:
print(f"IP: {received.psrc} - MAC: {received.hwsrc}")
Getting Started
To get started with Scapy:
-
Install Scapy:
pip install scapy
-
Import Scapy in your Python script:
from scapy.all import *
-
Start using Scapy functions, for example:
# Send a ping and wait for a response reply = sr1(IP(dst="8.8.8.8")/ICMP()) print(reply.summary())
Note: Some Scapy functions require root/administrator privileges to run properly.
Competitor Comparisons
fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols
Pros of dpkt
- Lightweight and fast packet parsing
- Simple and straightforward API
- Efficient memory usage
Cons of dpkt
- Less comprehensive protocol support
- Limited packet manipulation capabilities
- Smaller community and fewer updates
Code Comparison
dpkt example:
import dpkt
def parse_packet(packet):
eth = dpkt.ethernet.Ethernet(packet)
if isinstance(eth.data, dpkt.ip.IP):
ip = eth.data
print(f"Source IP: {ip.src}")
Scapy example:
from scapy.all import *
def parse_packet(packet):
if IP in packet:
ip = packet[IP]
print(f"Source IP: {ip.src}")
Both libraries offer packet parsing capabilities, but Scapy provides a more intuitive and feature-rich API. dpkt is more lightweight and efficient, while Scapy offers extensive protocol support and packet manipulation tools.
Scapy is generally preferred for complex network tasks and security research, while dpkt is suitable for high-performance packet processing in simpler scenarios. The choice between the two depends on the specific requirements of your project, balancing between speed, features, and ease of use.
Simple, secure & standards compliant web server for the most demanding of applications
Pros of uWebSockets
- Higher performance and scalability for WebSocket applications
- Lower memory footprint and CPU usage
- Supports both WebSocket and HTTP protocols in a single library
Cons of uWebSockets
- More focused on WebSocket functionality, less versatile for general networking tasks
- Steeper learning curve for beginners
- Less extensive documentation compared to Scapy
Code Comparison
uWebSockets (C++):
uWS::App().ws<PerSocketData>("/*", {
.open = [](auto *ws, auto *req) {
// WebSocket opened
},
.message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
ws->send(message, opCode);
}
}).listen(9001, [](auto *listen_socket) {
if (listen_socket) {
std::cout << "Listening on port " << 9001 << std::endl;
}
}).run();
Scapy (Python):
from scapy.all import *
def packet_callback(packet):
if packet.haslayer(TCP):
print(packet.summary())
sniff(filter="tcp", prn=packet_callback)
Summary
While uWebSockets excels in WebSocket performance and efficiency, Scapy offers broader networking capabilities and easier learning for beginners. uWebSockets is ideal for high-performance WebSocket applications, while Scapy is better suited for general network analysis and packet manipulation tasks.
Read-only mirror of Wireshark's Git repository at https://gitlab.com/wireshark/wireshark. ⚠️ GitHub won't let us disable pull requests. ⚠️ THEY WILL BE IGNORED HERE ⚠️ Upload them at GitLab instead.
Pros of Wireshark
- More comprehensive GUI for packet analysis and visualization
- Broader protocol support and deeper packet inspection capabilities
- Larger community and more extensive documentation
Cons of Wireshark
- Heavier resource usage and slower performance for large captures
- Less flexibility for custom packet manipulation and creation
- Steeper learning curve for advanced scripting and automation
Code Comparison
Scapy (Python):
from scapy.all import *
packet = IP(dst="8.8.8.8")/TCP(dport=80)
send(packet)
Wireshark (Lua):
local tap = Listener.new("frame")
function tap.packet(pinfo,tvb,ip)
print("Packet: " .. tostring(pinfo.number))
end
While Scapy excels in packet crafting and manipulation, Wireshark's strength lies in its comprehensive packet analysis capabilities. Scapy offers a more programmatic approach, allowing users to easily create and send custom packets. Wireshark, on the other hand, provides a robust GUI and extensive protocol dissectors for in-depth packet inspection and analysis.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Scapy
Scapy is a powerful Python-based interactive packet manipulation program and library.
It is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, store or read them using pcap files, match requests and replies, and much more. It is designed to allow fast packet prototyping by using default values that work.
It can easily handle most classical tasks like scanning, tracerouting, probing,
unit tests, attacks or network discovery (it can replace hping
, 85% of nmap
,
arpspoof
, arp-sk
, arping
, tcpdump
, wireshark
, p0f
, etc.). It also
performs very well at a lot of other specific tasks that most other tools can't
handle, like sending invalid frames, injecting your own 802.11 frames, combining
techniques (VLAN hopping+ARP cache poisoning, VoIP decoding on WEP protected
channel, ...), etc.
Scapy supports Python 3.7+. It's intended to be cross platform, and runs on many different platforms (Linux, OSX, *BSD, and Windows).
Getting started
Scapy is usable either as a shell or as a library. For further details, please head over to Getting started with Scapy, which is part of the documentation.
Shell demo
Scapy can easily be used as an interactive shell to interact with the network.
The following example shows how to send an ICMP Echo Request message to
github.com
, then display the reply source IP address:
sudo ./run_scapy
Welcome to Scapy
>>> p = IP(dst="github.com")/ICMP()
>>> r = sr1(p)
Begin emission:
.Finished to send 1 packets.
*
Received 2 packets, got 1 answers, remaining 0 packets
>>> r[IP].src
'192.30.253.113'
Resources
The documentation contains more advanced use cases, and examples.
Other useful resources:
- Scapy in 20 minutes
- Interactive tutorial (part of the documentation)
- The quick demo: an interactive session (some examples may be outdated)
- HTTP/2 notebook
- TLS notebooks
Installation
Scapy works without any external Python modules on Linux and BSD like operating systems. On Windows, you need to install some mandatory dependencies as described in the documentation.
On most systems, using Scapy is as simple as running the following commands:
git clone https://github.com/secdev/scapy
cd scapy
./run_scapy
To benefit from all Scapy features, such as plotting, you might want to install
Python modules, such as matplotlib
or cryptography
. See the
documentation and
follow the instructions to install them.
License
Scapy's code, tests and tools are licensed under GPL v2.
The documentation (everything unless marked otherwise in doc/
, and except the logo) is licensed under CC BY-NC-SA 2.5.
Contributing
Want to contribute? Great! Please take a few minutes to read this!
Top Related Projects
fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols
Simple, secure & standards compliant web server for the most demanding of applications
Read-only mirror of Wireshark's Git repository at https://gitlab.com/wireshark/wireshark. ⚠️ GitHub won't let us disable pull requests. ⚠️ THEY WILL BE IGNORED HERE ⚠️ Upload them at GitLab instead.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot