If you are interested in sniffing packets on your local network, this recipe can be used as the starting point. Remember that you may not be able to sniff packets other than what is destined to your machine, as decent network switches will only forward traffic that is designated for your machine.
Sniffing packets on your network
Getting ready
You need to install the pylibpcap library (Version 0.6.4 or greater) for this recipe to work. In Debian-based Linux systems, you may install it using the following command:
$ sudo apt-get install python-libpcap
It is also available at SourceForge (http://sourceforge.net/projects/pylibpcap/).
Python 3 may require you to install pypcap using pip instead:
$ sudo pip install pypcap ...