Scapy:eth_boundary 选项返回 IndexError:未找到层 [14] [英] Scapy: eth_boundary option returns IndexError: Layer [14] not found

查看:104
本文介绍了Scapy:eth_boundary 选项返回 IndexError:未找到层 [14]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设置 eth_boundary 选项时遗漏了一些东西.

<预><代码>>>>eth_boundary=14>>>pkt=e/i>>>长度(e)14>>>连(一)20>>>>>>pkt.show()###[ 生的 ]###负载= '\x00\xa0\xa1\x12\xc2\xc1\x001H\xcd\xe8\x5c\x08\x00E\x00\x00\x11\x00\x01\x00\x00@\x00P\xe2\x11\x01\x02\x14\x01\x01\x01'>>>pkt[eth_boundary:]回溯(最近一次调用最后一次):运行代码中的文件/usr/lib/python3.5/code.py",第 91 行exec(代码,self.locals)文件<console>",第 1 行,在 <module> 中文件/home/regress/scapy/scapy/packet.py",第 1171 行,在 __getitem__ 中raise IndexError("找不到层 [%s]" % lname)索引错误:未找到层 [14]>>>

请帮助我解决上述错误.

解决方案

问题

这里的问题是您像字节数组一样访问 pkt当它实际上是一个层数组时:

>>>pkt=以太()/IP()>>>包[0]<以太网类型=0x800 |<IP |>>>>>包[1]<IP|>>>>包[2]索引错误:未找到层 [2]

该错误准确描述了它看到的问题:Layer [14] not found

解决方案

使用 raw(pkt) 代替:

>>>eth_boundary = 14>>>pkt=以太()/IP()>>>原料(包)b'\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x08\x00E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01'>>>原始(包)[14:]b'E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01'

I'm missing something while setting eth_boundary option.

>>> eth_boundary=14
>>> pkt=e/i
>>> len(e)
14
>>> len(i)
20
>>>
>>> pkt.show()
###[ Raw ]###
  load= '\x00\xa0\xa1\x12\xc2\xc1\x001H\xcd\xe8\x5c\x08\x00E\x00\x00\x11\x00\x01\x00\x00@\x00P\xe2\x11\x01\x01\x02\x14\x01\x01\x01'

>>> pkt[eth_boundary:]
Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/home/regress/scapy/scapy/packet.py", line 1171, in __getitem__
    raise IndexError("Layer [%s] not found" % lname)
IndexError: Layer [14] not found
>>>

Please help me out on how to fix the above error.

解决方案

Problem

The problem here is that you are accessing pkt like an array of bytes when it's actually an array of layers:

>>> pkt=Ether()/IP()
>>> pkt[0]
<Ether  type=0x800 |<IP  |>>
>>> pkt[1]
<IP  |>
>>> pkt[2]
IndexError: Layer [2] not found

The error describes the problem it sees exactly: Layer [14] not found

Solution

Use raw(pkt) instead:

>>> eth_boundary = 14
>>> pkt=Ether()/IP()
>>> raw(pkt)
b'\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x08\x00E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01'
>>> raw(pkt)[14:]
b'E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01'

这篇关于Scapy:eth_boundary 选项返回 IndexError:未找到层 [14]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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