如何在 scapy 中创建自定义 top-level 层 2 header?
How to create a custom top-level layer 2 header in scapy?
假设我有以下内容:
class Delimiter(Packet):
name = "Delimiter"
fields_desc = [
ByteField("val", 0)
]
class OutHeader(Packet):
name = "Out Header"
fields_desc = [
ShortField("index", 0)
]
bind_layers(Delimiter, OutHeader, val=0)
bind_layers(OutHeader, Ether)
我想将 Delimeter
设为第 2 层 header,这样数据包顶部就没有以太币 header。我怎样才能做到这一点?仅使用这段代码,Scapy 就会改为读取:
###[ 802.3 ]###
dst = 00:51:99:ff:ff:ff
src = ff:ff:ff:00:00:00
len = 0
###[ Padding ]###
我最终通过手动切掉 headers 解决了这个问题,没有自定义数据包 objects:
s = str(pkt).encode("hex")
delim = int(s[:2])
index = int(s[2:6], 16)
rest = Ether(s[6:].decode("hex"))
假设我有以下内容:
class Delimiter(Packet):
name = "Delimiter"
fields_desc = [
ByteField("val", 0)
]
class OutHeader(Packet):
name = "Out Header"
fields_desc = [
ShortField("index", 0)
]
bind_layers(Delimiter, OutHeader, val=0)
bind_layers(OutHeader, Ether)
我想将 Delimeter
设为第 2 层 header,这样数据包顶部就没有以太币 header。我怎样才能做到这一点?仅使用这段代码,Scapy 就会改为读取:
###[ 802.3 ]###
dst = 00:51:99:ff:ff:ff
src = ff:ff:ff:00:00:00
len = 0
###[ Padding ]###
我最终通过手动切掉 headers 解决了这个问题,没有自定义数据包 objects:
s = str(pkt).encode("hex")
delim = int(s[:2])
index = int(s[2:6], 16)
rest = Ether(s[6:].decode("hex"))