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