I have an app which launches virtual hosts. I noticed that memory is building up quickly overtime. After many many trials of trying to find the cause, it turns out that the cause is using stop_filter
in scapy
.
The following simplified code is runnable, you can just copy/paste:
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)
Of course, you need to change the adapter and the IP. Also, use ping -t
to IP while running the code so the stopFilter()
works. After only a few moments you can see the memory is building up. I think similar issue in C with libpcap.
Any idea how to solve this?
Environment: Python 3.6.0, Win 7, Scapy 2.4.0 (same issue in Scapy 2.4.2)