0

I wrote a simple program to listen for packets over networks and output the information that I need to a default dict so I can examine the info later ,now when i run that script everything goes as I intentionally wanted , the cap_pkts function outputs for random n times and then my program freezes , if you want to regenerate this you can use any packet handler function as i am very sure it has nothing to do with my program freezing or at least not print any thing after n random times , i can't seem to know for sure does the script freeze or does it crash.

the packet handler function adds info to the default dict to keep track of info.

As far as i know a daemon thread keeps on executing after the script is done because it is a deamon thread right?

I am using visual studio code as my ide with python 3.8.2 64bit .

(n) is a random number of times that the program out puts the print statement in cap_pkts function

from scapy.all import * 

import sys 

import time 

import threading 


from collections import defaultdict ,Counter


ap_dict = defaultdict()

def PacketHandler():
    pass

def cap_pkts():

    ST =  time.time()
    i =0 
    while time.time() - ST < 60 :
        i +=1 
        print ( i ,i )
        res =  sniff(iface="wlan1mon", prn = PacketHandler , count=500)


        print (len(ap_dict))
    return 



if __name__ == "__main__":
    sniffing_thread = threading.Thread(target=cap_pkts , daemon=True )


    sniffing_thread.start()

    while True:
        print (ap_dict)
        time.sleep(3)
        pass
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Sec Team
  • 47
  • 8
  • If I read your code right, the main thread starts the cap_pkts thread and then just waits and prints ap_dict. The cap_pkts thread is looping for 60 seconds where it captures 500 packets, prints the length of ap_dict and if the 60 seconds are not over, starts again. Are you sure that you're not simply with an empty ap_dict (so no output from main) and got over 500 packets after 60 seconds ? Because in that case, the thread terminated and the main won't print anything. Try `print("Quitting thread", len(ap_dict))` and in the main loop `print("Main heartbeat", ap_dict)` – Eric Darchis Jun 05 '20 at 09:04
  • Please post a __proper__ [mcve] – bruno desthuilliers Jun 05 '20 at 09:53
  • the ap_dict is indeed empty when the program starts , the packet handler function is responsible for adding values to the ap_dict – Sec Team Jun 05 '20 at 18:55

0 Answers0