

When using Image Name, run “ taskkill /IM /IM /F” for example “ taskkill /IM ctfmon.exe /F” to kill CTF Loader.when using PID run “ taskkill /PID /PID /F“, for example, “ taskkill /PID 11024 /F” to kill CTF Loader.Print "Exiting the packet capture thread. If len(lect(,, , 0.1)) > 0:Īnd then to actually tell the thread to stop you just set the event: if cap_flg: # the process to say things, so we can see if # Make sure to not block forever waiting for You also need to make sure that the process doesn't sit waiting forever for output from the process, and ignoring the termination event, by only reading from the pipe if there is data available: def wire_cap(ip1,ip2,op_fold,file_name,duration,event): # invoke tshark to capture traffic during session In that while loop, have the watching thread check the event on every iteration, and stop the loop (and also probably kill the tshark it started) if it is set. Th_capture = threading.Thread(target=wire_cap, name='Thread_Packet_Capture', args=(IP1, IP2, output, 'wire_capture', 0, thread_kill)) The threading.Event() approach is on the right track, but you need the event to be visible in both threads, so you need to create it before you start the second thread and pass it in: if cap_flg: The above code I tried doesn't seem to work. I would like to know how can I make the process stop when I feel like stopping it (Like an exit condition that can be added so that I can exit the thread execution). 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.
