python构造数据包库_scapy:基于python的交互式数据包处理程序和库

Scapy是一个强大的Python库,用于交互式地操纵和构造网络包。它可以处理多种协议的包,进行扫描、追踪、探测等任务,替代多个网络工具。Scapy支持Python 2.7和3.4到3.8版本,可在Linux、OSX、*BSD和Windows等多个平台上运行。要开始使用,只需运行提供的shell命令,并通过实例展示了如何发送ICMP请求并获取回复的源IP地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

6e1c83a8ee0effd5ae607542e1b37371.png

Scapy

68747470733a2f2f7472617669732d63692e636f6d2f7365636465762f73636170792e7376673f6272616e63683d6d617374657268747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f6f73303364616f74666a6130777470372f6272616e63682f6d61737465723f7376673d7472756568747470733a2f2f636f6465636f762e696f2f67682f7365636465762f73636170792f6272616e63682f6d61737465722f67726170682f62616467652e73766768747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f333065653637373262623236346136383961323630346635636462303433376268747470733a2f2f696d672e736869656c64732e696f2f707970692f762f73636170792e73766768747470733a2f2f696d672e736869656c64732e696f2f707970692f707976657273696f6e732f73636170792e73766768747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c25323076322d626c75652e73766768747470733a2f2f6261646765732e6769747465722e696d2f7365636465762f73636170792e737667

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 2.7 and Python 3 (3.4 to 3.8). 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

68747470733a2f2f7365636465762e6769746875622e696f2f66696c65732f646f632f616e696d6174696f6e2d73636170792d696e7374616c6c2e737667

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 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.

Contributing

Want to contribute? Great! Please take a few minutes to read this!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值