

Print "Exiting the packet capture thread."

Th_capture = threading.Thread(target=wire_cap, name='Thread_Packet_Capture', args=(IP1, IP2, output, 'wire_capture', 0, )) Print "Starting a packet capture thread." I also tried threading.Event() as follows: if cap_flg: I tried using thread.exit() but it acted like sys.exit() and stopped the execution of the program completely.

Stop the thread or the background process wire_captureīy reading a bit, I realized that thread.start_new_thread() and threading.Thread() seems to be suitable only when I know the duration of the capture (an exit condition). Something like: Start a thread or a background process called wire_capture P = subprocess.Popen(cmd, shell=True,stderr=subprocess.PIPE)įor debugging purpose, I would like to run this function in the background by calling it as and when required and stopping it when I've got the capture. I would like to invoke the function I wrote for capture: def wire_cap(ip1,ip2,op_fold,file_name,duration): # invoke tshark to capture traffic during sessionĬmd='"tshark" -i 1 -P -w '+ op_fold+file_name+'.pcap src ' + str(ip1) + ' or src '+ str(ip2)Ĭmd='"tshark" -i 1 -a duration:'+str(duration)+' -P -w '+ op_fold+file_name+'.pcap src ' + str(ip1) + ' or src '+ str(ip2) I would like to do a packet capture using tshark, a command-line flavor of Wireshark, while connecting to a remote host device on telnet.
