我知道我可以将Raw
数据附加到像这样的scapy数据包
>>> p=Ether()/Raw("somedata")
>>> hexdump(p)
WARNING: Mac address to reach destination not found. Using broadcast.
0000 FF FF FF FF FF FF 00 00 00 00 00 00 90 00 73 6F ..............so
0010 6D 65 64 61 74 61 medata
>>>
此处数据以ASCII格式附加。
但是我怎么能只将数字附加到像这样的数据包上呢?
# Not real
>>> p = Ether()/RawNumbers(0x1234567891)
>>> hexdump(p)
WARNING: Mac address to reach destination not found. Using broadcast.
0000 FF FF FF FF FF FF 00 00 00 00 00 00 90 00 12 34 ................
0010 56 78 91 ...
>>>
也许我可以编写一个Packet-subclass来执行此操作,但我不确定如何实现它。有什么想法吗?
答案 0 :(得分:1)
不需要RawNumbers
层,因为您可以使用python内置功能实现此目的。请注意,如果您的图层只是一个字符串,scapy将默认为原始图层。
>>> hexdump(Ether()/"\x12\x34\x56\x78\x91")
WARNING: Mac address to reach destination not found. Using broadcast.
0000 FF FF FF FF FF FF 00 00 00 00 00 00 90 00 12 34 ...............4
0010 56 78 91 Vx.
或(更方便)
>>> hexdump(Ether()/"1234567891".decode("hex"))
WARNING: Mac address to reach destination not found. Using broadcast.
0000 FF FF FF FF FF FF 00 00 00 00 00 00 90 00 12 34 ...............4
0010 56 78 91 Vx.