[Python] How do I sucessfully stop TCPDump recording?

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am very new to python. My current project is to create a basic Tkinter window to start and stop a TCPdump Ethernet recording using a couple of buttons. I have been able to start a recording using a combination of subprocess and multiprocessing.So far I have been unsuccessful stopping the recording. I'm after advice on how to achieve this. Thanks. The code is being run on a raspberry pi 5

    import tkinter as tk
    import subprocess
    import multiprocessing
    import time


    # tcpdump configuration & subprocess creation

    def tcpdump_config():
    test_entry_str = test_entry.get()
    tcpdump_command = ['sudo', 'tcpdump', '-i', 'eth0', '-n', '-w', '/home/inst/Documents/Test' + str(test_entry_str) + '.pcap']
    proc = subprocess.run(tcpdump_command, shell = False)

    # Start recording process
    def rec_start():
    if test_entry.get() == "":
    from tkinter import messagebox
    messagebox.showinfo(title="Information", message="Enter Test Number")
    else:
    m1 = multiprocessing.Process(target=tcpdump_config ,daemon=True, name='m1')
    m1.start()


    # Stop subprocess
    def rec_stop():
    pass


    I have tried unsuccessfully using the terminate and kill commands in various forms and the process continues to run.

    Continue reading...

Compartilhe esta Página