【发布时间】:2019-03-19 05:58:45
【问题描述】:
我有一个启动虚拟主机的应用程序。我注意到记忆力随着时间的推移而迅速增加。经过多次尝试寻找原因,结果发现原因是在scapy中使用了stop_filter。
以下简化代码是可以运行的,你可以复制/粘贴:
from scapy.all import *
import threading
from time import sleep
def stopFilter(packet):
if ICMP in packet:
if packet[1].dst == '192.168.0.70':
print('packet found')
return True
def host():
while True:
sniff(iface="Intel(R) PRO/1000 PT Dual Port Server Adapter #2", timeout=2, stop_filter=stopFilter, store=0)
sleep(2)
for i in range(200):
print(i)
t = threading.Thread(target=host)
t.start()
sleep(0.1)
当然,您需要更改适配器和 IP。此外,在运行代码时将ping -t 用于IP,以便stopFilter() 工作。片刻之后,您就可以看到内存正在建立。 I think similar issue in C with libpcap.
知道如何解决这个问题吗?
环境: Python 3.6.0、Win 7、Scapy 2.4.0(Scapy 2.4.2 中的相同问题)
【问题讨论】:
标签: python python-3.x memory-leaks scapy libpcap