简体   繁体   English

如何使用Scapy在Python中删除数据包的尾部

[英]How to remove trailer of the packet in python using scapy

I'm reading a pcap file in python using scapy which contains Ethernet packets that have trailer. 我正在使用scapy在python中读取pcap文件,其中包含具有尾部的以太网数据包。 How can I remove these trailers? 如何移除这些拖车?

PS: Ethernet packets can not be less than 64 bytes (including FCS).Network adapters add padding zero bytes to end of the packet to overcome this problem. PS:以太网数据包不能少于64个字节(包括FCS)。网络适配器在数据包末尾添加填充零字节来解决此问题。 These padding bytes called "Trailer". 这些填充字节称为“预告片”。 See here for more information. 有关更多信息,请参见此处

It seems there is no official way to remove it. 似乎没有官方的方法可以删除它。 This work on frames that have IPv4 as network layer protocol: 这适用于将IPv4作为网络层协议的帧:

packet_without_trailer=IP(str(packet[IP])[0:packet[IP].len])

只需使用较高的层,而忽略以太网层:

packet = eval(originalPacket[IP])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM