Python Scapy: How to stop sniff() function manually

How to stop scapy sniff() function to stop, simply use stop_filter parameter to pass a function

Here’s an example

Announce an Event in python:

e = Event()

Then write a function to stop sniff()

def stop_sniff():
    e.set()

Now finish the function to start sniff() and pass the Event e to the stop_filter

def start_sniff():
    e.clear()
    sniff(iface='ASUS PCE-AC88 802.11ac Network Adapter',
          filter="dst host 192.168.31.5 or src host 192.168.31.5", 
          prn=process_sniffed_packet,
          stop_filter=lambda x: e.is_set())

Now sniff() will stop each time you call the stop_sniff() function and restart when you call start_sniff().

Leave a Comment

Your email address will not be published.