PyPCAP¶
This is a simplified object-oriented Python wrapper for libpcap - the current tcpdump.org version, and the WinPcap port for Windows.
Example use:
>>> import pcap
>>> sniffer = pcap.pcap(name=None, promisc=True, immediate=True)
>>> addr = lambda pkt, offset: '.'.join(str(ord(pkt[i])) for i in xrange(offset, offset + 4)).ljust(16)
>>> for ts, pkt in sniffer:
... print ts, '\tSRC', addr(pkt, sniffer.dloff + 12), '\tDST', addr(pkt, sniffer.dloff + 16)
...
Windows notes¶
WinPcap has compatibility issues with Windows 10, therefore it’s recommended to use Npcap (Nmap’s packet sniffing library for Windows, based on the WinPcap/Libpcap libraries, but with improved speed, portability, security, and efficiency). Please enable WinPcap API-compatible mode during the library installation.
The sample installation using Chocolatey:
choco install -y npcap --ia '/winpcap_mode=yes'
Installation¶
This package requires:
- libpcap-dev
- python-dev
To install run
pip install pypcap
Installation from sources¶
Please clone the sources and run:
python setup.py install
Note for Windows users: Please download the WinPcap Developer’s Pack, unpack the archive and put it into the sibling directory as wpdpack
(setup.py
will discover it).
Sample procedure in PowerShell:
cd ..
wget -usebasicparsing -outfile WpdPack_4_1_2.zip http://www.winpcap.org/install/bin/WpdPack_4_1_2.zip
unzip WpdPack_4_1_2.zip
cd pypcap
python setup.py install
Support¶
Visit https://github.com/pynetwork/pypcap for help!
Help the Project¶
Contributing¶
Report a Bug or Make a Feature Request¶
Please go to the GitHub Issues page: https://github.com/pynetwork/pypcap/issues.
Checkout the Code¶
git clone https://github.com/pynetwork/pypcap.git
Become a Developer¶
pypcap uses the ‘GitHub Flow’ model: GitHub Flow
- To work on something new, create a descriptively named branch off of master (ie: my-awesome)
- Commit to that branch locally and regularly push your work to the same named branch on the server
- When you need feedback or help, or you think the branch is ready for merging, open a pull request
- After someone else has reviewed and signed off on the feature, you can merge it into master
New Feature or Bug¶
$ git checkout -b my-awesome $ git push -u origin my-awesome $ <code for a bit>; git push $ <code for a bit>; git push $ tox (this will run all the tests)
- Go to github and hit ‘New pull request’
- Someone reviews it and says ‘AOK’
- Merge the pull request (green button)