简体   繁体   English

将 PTPv2 层添加到 scapy

[英]Adding PTPv2 layer to scapy

I want to add a PTPv2 Layer to scapy (v2.3.3) in python (v2.7).我想在 python (v2.7) 中向 scapy (v2.3.3) 添加 PTPv2 层。 I added the ptpv2 class with the PTP entries to the file /scapy/layers/inet.py (because PTP is at layer 4).我将带有 PTP 条目的 ptpv2 类添加到文件 /scapy/layers/inet.py(因为 PTP 位于第 4 层)。 I also bound the ptpv2 layer to the upper layer, in my case Ethernet.我还将 ptpv2 层绑定到上层,在我的例子中是以太网。

bind_layers(Ethernet,ptpv2)

By typing the scapy command "ls()" the created ptpv2 layer is listed, ok, success.通过键入 scapy 命令“ls()”,列出了创建的 ptpv2 层,ok,成功。 But by accessing the layer through the python commands但是通过python命令访问层

for packet in PcapReader('/media/sf_SharedFolder/test.pcap'):
  if packet[ptpv2].sequenceId == anything:
    # do sth

the following error occurs:出现以下错误:

File "/usr/lib/python2.7/dist-packages/scapy/packet.py", line 817, in __getitem__
  raise IndexError("Layer [%s] not found" % lname)
IndexError: Layer [ptpv2] not found

The Wireshark file has the layers Frame -> Ethernet -> PTP, so my binding command has to be right. Wireshark 文件具有层 Frame -> Ethernet -> PTP,所以我的绑定命令必须是正确的。

Don't know where the error is.不知道错误在哪里。

Pls, help me!请帮助我!

Thx谢谢

Chris克里斯

Your dissector is probably failing, but Scapy hides that and decodes the layer as Raw() .您的解剖器可能失败了,但 Scapy 隐藏了它并将该层解码为Raw()

You can:你可以:

  • check that by checking that packet.payload is a Raw instance.通过检查packet.payload是一个Raw实例来检查。
  • try to find what crashes in your dissector by setting conf.debug_dissector = True .尝试通过设置conf.debug_dissector = True来查找解剖器中崩溃的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM