Scapy:eth_boundary选项返回IndexError:找不到图层[14]

问题描述 投票:1回答:1

我在设置eth_boundary选项时丢失了某些内容。

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

请帮助我解决上述错误。

python scapy
1个回答
0
投票

问题

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

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

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

解决方案

改为使用raw(pkt):

>>> 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'
© www.soinside.com 2019 - 2024. All rights reserved.