如何从 pcap 文件中删除以太网层?

发布于 2024-09-25 23:20:57 字数 82 浏览 2 评论 0原文

我有一个用 Wireshark 捕获的 pcap。 Wireshark 中是否有任何函数可以从结果中剥离以太网层?或者有什么命令行工具可以做到这一点?

I have a pcap captured with Wireshark. Is there any function in Wireshark that will strip Ethernet layer from the result? Or any command line tool to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一影成城 2024-10-02 23:20:57

我搜索了更多有关 pcap 编辑器的信息,发现这有效:

$ bittwiste -I a.pcap -O b.pcap -M 12 -D 1-14

-M 12 将链接类型设置为 RAW
-D 1-14 删除链接数据层中的字节 1-14(以太网帧长 14 个字节)

当我在 Wireshark 中打开结果时,我看到“原始数据包数据(无可用链接信息)”和下面的 IP 帧。这就是我所需要的。

I searched a bit more about pcap editors, and I found that this works:

$ bittwiste -I a.pcap -O b.pcap -M 12 -D 1-14

-M 12 sets link type to RAW
-D 1-14 deletes bytes 1-14 in link data layer (Etherenet frame is 14 bytes long)

When I open up result in Wireshark I see "Raw packet data (No link information available)" and IP frame below. So this is what I needed.

掩于岁月 2024-10-02 23:20:57

假设输出中所需的第一层是 IP,则以下两种方法都可以工作。请注意,如果以太网层后面是 IP,则 editcap 过程只会生成有效的 pcap 文件。 scapy 路线可以说更可靠,并且可以定制以适应更复杂的层堆栈。

editcap

editcap -C 14 -L -T rawip ./eth.pcap ./eth_stripped.pcap

scapy:

#!/usr/bin/env python3
from scapy.layers.inet import IP
from scapy.utils import PcapWriter, rdpcap


pkts = rdpcap("./eth.pcap")
pw = PcapWriter("./eth_stripped.pcap")
for pkt in pkts:
    # Or `out = pkt.payload` if the layer after eth is valid pcap format.
    out = pkt[IP]
    pw.write(out)

pw.close()

Assuming the desired first layer in the output is IP, the two methods below can work. Note that the editcap procedure will only produce a valid pcap file if the Ethernet layer is followed by IP. The scapy route is arguable more reliable and can be tailored to work with more complex layer stacks.

editcap:

editcap -C 14 -L -T rawip ./eth.pcap ./eth_stripped.pcap

scapy:

#!/usr/bin/env python3
from scapy.layers.inet import IP
from scapy.utils import PcapWriter, rdpcap


pkts = rdpcap("./eth.pcap")
pw = PcapWriter("./eth_stripped.pcap")
for pkt in pkts:
    # Or `out = pkt.payload` if the layer after eth is valid pcap format.
    out = pkt[IP]
    pw.write(out)

pw.close()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文