使用python创建一个pcap文件 [英] creating a pcap file using python

查看:127
本文介绍了使用python创建一个pcap文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个非常简单的 PCAP 文件(1 个 UDP 消息).
尝试使用 dpkt (pcap.Writer),没有运气,而且文档很少.
任何人都可以发布一个工作示例吗?
(或任何其他替代方案 - 我不受 dpkt 的约束)

I'm trying to create a very simple PCAP file (1 UDP message).
Tried using dpkt (pcap.Writer), no luck, and the documentation is scarce.
Can anyone post a working example?
(or any other alternative - I'm not bound to dpkt)

推荐答案

您可以使用 Scapy.

You may use Scapy.

https://scapy.readthedocs.io/en/latest/installation.html

如果使用 Python 3:

If using Python 3:

pip3 install scapy

然后在 Python 中:

Then in Python:

from scapy.all import wrpcap, Ether, IP, UDP
packet = Ether() / IP(dst="1.2.3.4") / UDP(dport=123)
wrpcap('foo.pcap', [packet])

这篇关于使用python创建一个pcap文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆