在python中使用scapy包中的PcapReader读取pcap文件时,抛出EOFError如何解决?
错误信息如下:
Traceback (most recent call last):
File "D:/学习/科研训练/wiresharkanasying/main.py", line 7, in <module>
map=Quantitystatistics.Quantitystatistics(s1)
File "D:\学习\科研训练\wiresharkanasying\Quantitystatistics.py", line 15, in __init__
self.map=self.Ethernet_prostatistics()
File "D:\学习\科研训练\wiresharkanasying\Quantitystatistics.py", line 22, in Ethernet_prostatistics
data = self.pcap.read_packet()
File "D:\Anaconda\lib\site-packages\scapy\utils.py", line 1038, in read_packet
rp = super(PcapReader, self).read_packet(size=size)
File "D:\Anaconda\lib\site-packages\scapy\utils.py", line 976, in read_packet
raise EOFError
EOFError
使用的pcap包是用wireshark随便抓取的一个包
在看了方法源码之后知道了抛出异常的原因:
def read_packet(self, size=MTU):
"""return a single packet read from the file as a tuple containing
(pkt_data, pkt_metadata)
raise EOFError when no more packets are available
"""
hdr = self.f.read(16)
if len(hdr) < 16:
raise EOFError
sec, usec, caplen, wirelen = struct.unpack(self.endian + "IIII", hdr)
return (self.f.read(caplen)[:size],
RawPcapReader.PacketMetadata(sec=sec, usec=usec,
wirelen=wirelen, caplen=caplen))
应该如何修改才能成功读取pcap包呢,或者说要对pcap包进行什么预处理吗