写了个python程序解析流量数据包,用的是scapy库。读取流量较少的pcap包文件时可以顺利运行,读取大点的pcap包就会报错。
错误信息如下:
Traceback (most recent call last):
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 235, in __getattr__
fld, v = self.getfield_and_val(attr)
TypeError: 'NoneType' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 235, in __getattr__
fld, v = self.getfield_and_val(attr)
TypeError: 'NoneType' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Paper\sta\pcap\特征提取.py", line 22, in <module>
bufLen.append(data.len)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 237, in __getattr__
return self.payload.__getattr__(attr)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 237, in __getattr__
return self.payload.__getattr__(attr)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 235, in __getattr__
fld, v = self.getfield_and_val(attr)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python36\lib\site-packages\scapy\packet.py", line 1291, in getfield_and_val
raise AttributeError(attr)
AttributeError: len
源代码部分:
from scapy.all import *
from scapy.utils import PcapReader
rd = PcapReader('./a.pcap')
while True:
data = rd.read_packet()
if data is None:
break
else:
'''
分析处理过程
'''
rd.close()
源代码处理过程应该没问题,毕竟可以运行处理小数据包,但数据量一大就会报错。
而且有时候不稳定,简单的同样的代码有时可以运行成功,有时也会报上面的错,我想是不是系统的问题,我用的是在windows10,内存16G应该足够大,为什么会报错呢,求大神解答!