写了个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应该足够大,为什么会报错呢,求大神解答!
提取的pcap包里有其他协议类型的数据包,像ARP包就没有len属性,会报错。把打开的包里的协议类型过滤一下。
我来给你整理下错误信息:
init.py", line 877, in
IFACES.load_from_powershell()
init.py", line 767, in load_from_powershell
ifaces_ips = get_ips()
init.py", line 495, in get_ips
['Description', 'IPAddress']):
init.py", line 225, in exec_query_ps
__init_.py", line 199, in query
self.process.stdin.flush()
OSError: [Errno 22] Invalid argument
仔细看看这些错误信息,也就估计能猜到是这个包的Bug,没有处理获取不到IP地址的情况,或者说兼容性没做好。在某些情况下,获取不到IP地址而抛出的异常。
具体的只有你自己调试看看了。。