Scripts2026年5月16日·1 分钟阅读

Scapy — Interactive Packet Manipulation in Python

A powerful Python-based interactive packet manipulation library and tool that can forge, decode, send, receive, and analyze network packets for security research, protocol testing, and network discovery.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Scapy Overview
通用 CLI 安装命令
npx tokrepo install 38ec3125-5121-11f1-9bc6-00163e2b0d79

Introduction

Scapy is a Python library and interactive tool for low-level network packet crafting, sending, sniffing, and analysis. Unlike fixed-function tools, Scapy gives full programmatic control over every byte of every protocol layer, making it the Swiss Army knife for network security research, protocol fuzzing, and custom scanning.

What Scapy Does

  • Crafts arbitrary packets at any protocol layer from Ethernet frames to application payloads
  • Sends packets on the wire and matches responses with automatic request-response correlation
  • Sniffs live traffic with BPF filters and dissects captured packets into structured Python objects
  • Supports 500+ protocols with automatic field decoding and pretty-printing
  • Generates network traces, pcap files, and protocol visualizations programmatically

Architecture Overview

Scapy represents packets as layered Python objects where each protocol is a class with typed fields. Layers stack via the / operator, and Scapy handles checksums, lengths, and padding automatically. The send/receive engine uses raw sockets or libpcap for transmission and employs a matching algorithm to pair requests with responses. An interactive shell (built on IPython) provides immediate feedback for exploratory packet work.

Self-Hosting & Configuration

  • Install via pip; requires root/sudo for raw socket operations
  • Works on Linux, macOS, and Windows (with Npcap for Windows raw socket support)
  • Configure default network interface with conf.iface in scripts or interactive shell
  • Use conf.route to inspect and modify the routing table for multi-interface setups
  • Integrate with Wireshark via wireshark() method for visual packet inspection

Key Features

  • 500+ built-in protocol dissectors covering L2 through L7 (Ethernet, IP, TCP, DNS, TLS, HTTP, etc.)
  • Programmatic packet crafting enables protocol fuzzing and custom scanner development
  • Built-in traceroute, arping, and sniff functions for common network tasks
  • Automatic pcap read/write for integration with tcpdump and Wireshark workflows
  • Extensible architecture allows defining custom protocols in a few lines of Python

Comparison with Similar Tools

  • Nmap — focused on host/port discovery and service detection; Scapy provides raw packet-level control for custom scanning logic
  • hping3 — CLI packet crafter limited to TCP/UDP/ICMP; Scapy covers all protocols and is fully scriptable in Python
  • Netcat — sends/receives raw TCP/UDP streams; Scapy operates at the packet level with protocol awareness
  • Wireshark — passive traffic analyzer; Scapy both generates and analyzes packets programmatically

FAQ

Q: Does Scapy require root privileges? A: Yes, for sending raw packets and sniffing. On Linux you can use capabilities (CAP_NET_RAW) instead of full root.

Q: Can Scapy handle high-throughput packet generation? A: Scapy prioritizes flexibility over raw speed. For high-rate scanning, use sendpfast() which leverages tcpreplay, or generate packets with Scapy and send via faster backends.

Q: How do I add a custom protocol dissector? A: Define a class inheriting from Packet with fields_desc listing field types and sizes. Bind it to parent layers with bind_layers().

Q: Is Scapy suitable for production network monitoring? A: Scapy is designed for research and testing. For production sniffing at scale, use dedicated tools like Zeek or Suricata and reserve Scapy for prototyping and analysis.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产