有人能帮我解决,如何模拟IP包的大小小于最小使用替罪羊。
我想将大小缩小到10,以验证错误计数器。
替罪羊
>>> i=IP(src="20.1.1.2",dst="20.1.1.1")
>>> len(i)
20 我需要降低这个值
发布于 2019-09-30 17:46:00
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'https://stackoverflow.com/questions/58164837
复制相似问题