Im trying to handle tcpdump output in python.
I need to run tcpdump (which captures packets and gives me information), and read the output and process it.
The problem is that tcpdump works all the time, and I need to read the package information as soon as it exits and continues to do so.
I tried to learn the python subprocess and tried calling tcpdump using popen and piping stdout, but it does not seem to work.
Any directions on how to do this.
import subprocess def redirect(): tcpdump = subprocess.Popen("sudo tcpdump...", stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True) while True: s = tcpdump.stdout.readline()
python subprocess popen tcpdump
ashish g
source share