pythonwiresharktcpdumpcap

How to generate Wireshark/tcpdump traces


I want to generate Wireshark/tcpdump traces at the end of a Python script, in a cap file.I looked at libcap for example but when executing the command, the script is stopped. How can I generate a cap file without suspending my intial python script? Thank you


Solution

  • You can start command in background:

    import os
    os.spawnl(os.P_NOWAIT, 'your_command')
    

    Or:

    import subprocess
    process = subprocess.Popen(['your_command', 'arg1', 'arg2'])