Capturing network traffic with Python

<p> It is necessary to capture the traffic on a specific network-interface between a server and a client. Most of the messages can be ignored, but some of them should be filtered and evaluated.<br /> This depends on the message-body. </p> <p> Other requirements: <li>The network-interface should be choosable from a list of all available devices.<li>The body should be readable by a human-beings. <li>only SYN-Packages, no ACKs<li>specific IP-Adresses </p> It should run on Linux.
1 answer

Capture network traffic with Pcapy

Description of Pcapy (http://oss.coresecurity.com/projects/pcapy.html):
"Pcapy is a Python extension module that interfaces with the libpcap packet capture library. Pcapy enables python scripts to capture packets on the network. Pcapy is highly effective when used in conjunction with a packet-handling package such as Impacket, which is a collection of Python classes for constructing and dissecting network packets."

Getting all available devices:
http://pastebin.com/fXfTwuU4

Start the sniffing:
http://pastebin.com/eWHGRA9q

Read the stream:
http://pastebin.com/xU9yy0pM

(I had to use links because correct indentation is important in python and not supported by this editor.)

Taggings: