0

How do i stop the following thread?

from threading import Thread
from scapy.all import sniff

class SnifferThread(Thread):
    def __init__ (self,filter):
        Thread.__init__(self)
        self.filter = filter

    def run(self):
        sniff(filter=self.filter, prn=self.pkt_callback, store=0)

    def pkt_callback(self,pkt):
        print pkt.sprintf('%TCP.payload%')

if __name__ == '__main__':
    sniffer = SnifferThread("tcp port 80")
    sniffer.start()
    #here i will make a GUI using PyQt4

Should i kill it somehow? If i do kill it will the memory be cleaned?

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by kapcom01
Featured Replies
  • 1

    Isn't it the join() method of the thread? Read More

  • [QUOTE=kapcom01;1049578]How do i stop the following thread? [CODE] from threading import Thread from scapy.all import sniff class SnifferThread(Thread): def __init__ (self,filter): Thread.__init__(self) self.filter = filter def run(self): sniff(filter=self.filter, prn=self.pkt_callback, store=0) def pkt_callback(self,pkt): print pkt.sprintf('%TCP.payload%') if __name__ == '__main__': sniffer = SnifferThread("tcp port 80") sniffer.start() #here i will make a GUI … Read More

  • Google found a patch for scapy.all..sniff, wich allows to stop the sniff function programmatically. You should try this [url=http://trac.secdev.org/scapy/wiki/PatchSelectStopperTimeout]http://trac.secdev.org/scapy/wiki/PatchSelectStopperTimeout[/url] Read More

1

How do i stop the following thread?

from threading import Thread
from scapy.all import sniff

class SnifferThread(Thread):
    def __init__ (self,filter):
        Thread.__init__(self)
        self.filter = filter

    def run(self):
        sniff(filter=self.filter, prn=self.pkt_callback, store=0)

    def pkt_callback(self,pkt):
        print pkt.sprintf('%TCP.payload%')

if __name__ == '__main__':
    sniffer = SnifferThread("tcp port 80")
    sniffer.start()
    #here i will make a GUI using PyQt4

Should i kill it somehow? If i do kill it will the memory be cleaned?

Yes. sniffer.join() should solve your problem.

0

No it doesn't work.:(
The problem is with the sniff(). I don't know if im doing this right.
It runs forever..
When i do the following i can stop it with KeyboardInterrupt:

from scapy.all import sniff

def pkt_callback(pkt):
    print pkt.sprintf('%TCP.payload%')

if __name__ == '__main__':
    try:
        sniff(filter="tcp port 80", prn=pkt_callback, store=0)
    except KeyboardInterrupt:
        exit(0)

But when it runs from a class it doesnt catch the KeyboardInterrupt.

0

wow:) That seems to be the solution!
Thank you all three of you!
@ Gribouillis : i'm checking it right now.. if it works i'll mark the thread as solved.

This question has already been answered. Start a new discussion instead.
Please be thoughtful and detailed and be sure to adhere to our posting rules.