Search code examples
pythontshark

Use a compiled program as input inside my python software


I've seen different softwares using compiled programs as a "module"; an example would be wifite which uses the aircrack suite.

Similarly, I need to implement tshark inside my python program but without having to work my way through the source code (mainly because I'd want the software to be modular and to leave tshark as a simple dependency).

What's the best way to do so? I'd avoid a simple call to the program as I don't feel it is very pythonic.


Solution

  • In a general sense, the generic API provided by standard UNIX programs consists of:

    • The argument vector with which that program is started (an array of C strings, as generated by a shell or passed directly to the subprocess module).
    • The file descriptors passed as FD 0, 1 and 2 (stdin, stdout and stderr) when that process is started (others may be used, but only these three are part of the standard API).
    • The set of environment variables inherited by that program at startup.
    • Various other inherited process state, such as the program's current working directory.

    Traditionally, UNIX programs communicate with each other via these means -- reading input from stdin (unless otherwise specified on command line), writing to stdout, logging to stderr, etc.

    Some programs may offer library interfaces, or socket-based interfaces, but these are available only on a case-by-case basis.

    If you are trying to interface with software written in C that provides a library interface, see the ctypes standard-library module.