Package: python-pcapng
Python library to parse the pcap-ng format used by newer versions
of dumpcap & similar tools (wireshark, winpcap, …).DocumentationIf you prefer the RTD theme, or want documentation for any version
other than the latest, head here:http://python-pcapng.readthedocs.org/en/latest/If you prefer the more comfortable, page-wide, default sphinx theme,
a documentation mirror is hosted on GitHub pages:http://rshk.github.io/python-pcapng/CI build statusBranchStatusmasterdevelopSource codeSource, issue tracker etc. on GitHub:https://github.com/rshk/python-pcapngGet the source from git:git clone https://github.com/rshk/python-pcapngDownload zip of the latest version:https://github.com/rshk/python-pcapng/archive/master.zipInstall from pypi:pip install python-pcapngPyPI statusThe official page on the Python Package Index is:https://pypi.python.org/pypi/python-pcapngWhy this library?I need to decently extract some information from a bunch of pcap-ng
files, but apparently tcpdump has some problems reading those files,I couldn’t find other nice tools nor Python bindings to a library
able to parse this format, so..In general, it appears there are (quite a bunch of!) Python modules
to parse the old (much simpler) format, but nothing for the new one.And, they usually completely lack any form of documentation.Isn’t it slow?Yes, I guess it would be much slower than something written in C,
but I’m much better at Python than C...and I need to get things done, and CPU time is not that expensive :)(Maybe I’ll give a try porting the thing to Cython to speed it up, but
anyways, pure-Python libraries are always useful, eg. for PyPy).How do I use it?Basic usage is as simple as:frompcapngimportFileScannerwithopen('/tmp/mycapture.pcap','rb')asfp:scanner=FileScanner(fp)forblockinscanner:pass# do something with the block...Have a look at the blocks documentation to see what they do; also, theexamplesdirectory contains some example scripts using the library.HackingFormat specification is here:https://github.com/pcapng/pcapng/Contributions are welcome, please contact me if you’re planning to do
some big change, so that we can sort out the best way to integrate it.Or even better, open an issue so the whole world can participate in
the discussion :)Pcap-ng write supportWrite support exists as of version 2.0.0. See the fileexamples/generate_pcapng.pyfor an example of the minimum code
needed to generate a pcapng file.In most cases, this library will prevent you from creating broken
data. If you want to create marginal pcapng files, e.g. as test cases
for other software, you can do that by adjusting the “strictness” of
the library, as in:frompcapng.strictnessimportStrictness,set_strictnessset_strictness(Strictness.FIX)Recognized values areStrictness.FORBID(the default),Strictness.FIX(warn about problems, fixif possible),Strictness.WARN(warn only), andStrictness.NONE(no warnings).
Circumstances that will result in strictness warnings include:Adding multiples of a non-repeatable option to a blockAdding a SPB to a file with more than one interfaceWriting a PB (PBs are obsolete and not to be used in new files)Writing EPB/SPB/PB/ISB before writing any IDBsCreating a releaseCreate a tag for the new version:git tag v2.0.0 -m 'Version 2.0.0'Install build dependencies in a virtualenv:python -m venv ./.build-venv
./.build-venv/bin/python -m pip install build twineBuild source and wheel distributions:rm -rf ./dist *.egg-info
./.build-venv/bin/python -m buildUse Twine to upload to pypi:twine upload dist/*TroubleshootingIf you get some crazy version number like2.0.1.dev0+g7bd8575.d20220310instead of what you expect (eg2.0.0), it’s because you have uncommitted or untracked files in
your local working copy, or you created more commits after creating
the tag. Such a version number will be refused by pypi (and it’s not a
good version number anyways), so make sure you have a clean working
copy before building.