Inspired by this StackOverflow question, [“How do I sniff on a port for log messages using python?”][so_question], I decided to figure out how to capture and process packets in Python. It turns out to be quite easy once you work out the kinks. Except the kinks were a pain to determine.
[so_question]: http://stackoverflow.com/q/28870666/47078
Sample output:
$ sudo python capture.py 10:27:44.016601 hello ('127.0.0.1', 61129) 10:27:44.016614 hello ('127.0.0.1', 61129) 10:27:54.019731 hello ('127.0.0.1', 61137) 10:27:54.019741 hello ('127.0.0.1', 61137)