Scapy 2.2
即使数据包不完整,scapy也会显示数据包fields_desc的所有字段。
您知道如何告诉用户字段实际上不存在吗?
from scapy.all import *
class test(Packet):
name = "Testing"
fields_desc = [
XByteField("prot", 0x12),
XByteField("fun1", 0x1),
XByteField("fun2", 0x2),
XByteField("fun3", 0x3),
XByteField("fun4", 0x4),
XByteField("fun5", 0x5),
]
>>> a = test()
>>> a.show2()
###[ Testing ]###
prot = 0x12
fun1 = 0x1
fun2 = 0x2
fun3 = 0x3
fun4 = 0x4
fun5 = 0x5
>>> normalPacket = test()
>>> normalPacket.show2()
###[ Testing ]###
prot = 0x12
fun1 = 0x1
fun2 = 0x2
fun3 = 0x3
fun4 = 0x4
fun5 = 0x5
# Building an incomplete packet: the last two fields are missing
>>> incompletePacket = test(str(normalPacket)[0:len(normalPacket) - 2])
>>> incompletePacket.show2()
###[ Testing ]###
prot = 0x12
fun1 = 0x1
fun2 = 0x2
fun3 = 0x3
fun4 = 0x4
fun5 = 0x5
>>> str(incompletePacket)
Out[24]:
'\x12\x01\x02\x03'
正如您所看到的,incompletePacket使用str()函数正确打印,但是当我想要显示它时(使用show()或show2()函数);甚至字段fun4和fun5都是打印的。
是否存在意外结束的scapy异常错误?