I have a script that runs tcpdump indefinitely, and outputs to a capture.out
file. I would like to write another Python script to monitor capture.out
and iterate over a loop each time a new line (or even better, a new packet) is written to the file by the other script.
I know how to loop through lines in a file, but I am not sure how to continuously monitor a file and iterate only when a new line (or packet) is written by the other script.
My ultimate goal is to publish each packet captured over MQTT (filtering out MQTT traffic of course), so if there is a more efficient solution to my end goal here, such as bypassing an output file and a simple way to make a Python function call on each packet captured by tcpdump, that would be even better.