有人可以帮我吗,如何使用Scapy模拟大小小于最小的IP数据包。
我想将大小减小到10以验证错误计数器。
从船头截断
I = IP(SRC = “20.1.1.2”,DST = “20.1.1.1”)
长度(I)20-需要降低此值
Scapy不允许您更改IP标头中的字节数。相反,您可以做的是将原始IP字节作为数据加载到eth有效负载之上。
这里我们将IP标头加载为字节。
>>> ip_data=IP(src="20.1.1.2",dst="20.1.1.1")
>>> raw(ip_data)
b'E\x00\x00\x14\x00\x01\x00\x00@\x00P\xe5\x14\x01\x01\x02\x14\x01\x01\x01'
>>> packet = Ether()/raw(ip_data)
我们可以将数据包中的原始字节视为一个数组,以仅查看IP标头“有效负载”的前10个(或所有)字节:
>>> packet_bytes = raw(packet)
WARNING: Mac address to reach destination not found. Using broadcast.
>>> eth_boundary = 14
>>> packet_bytes[eth_boundary:] # All IP bytes
b'E\x00\x00\x14\x00\x01\x00\x00@\x00P\xe5\x14\x01\x01\x02\x14\x01\x01\x01'
>>> packet_bytes[eth_boundary:eth_boundary+10] # Only first 10 bytes
b'E\x00\x00\x14\x00\x01\x00\x00@\x00'