Skip to main content

Library to read/write the pcap-ng format used by various packet sniffers

Project description

Python-pcapng

Python library to parse the pcap-ng format used by newer versions of dumpcap & similar tools (wireshark, winpcap, …).

Documentation

If 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 status

Branch

Status

master

https://travis-ci.org/rshk/python-pcapng.svg?branch=master

develop

https://travis-ci.org/rshk/python-pcapng.svg?branch=develop

Source code

Source, issue tracker etc. on GitHub: https://github.com/rshk/python-pcapng

Get the source from git:

git clone https://github.com/rshk/python-pcapng

Download zip of the latest version:

https://github.com/rshk/python-pcapng/archive/master.zip

Install from pypi:

pip install python-pcapng

PyPI status

The official page on the Python Package Index is: https://pypi-hypernode.com/pypi/python-pcapng

Latest PyPI version Number of PyPI downloads Supported Python versions Development Status License

Why 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:

from pcapng import FileScanner

with open('/tmp/mycapture.pcap', 'rb') as fp:
    scanner = FileScanner(fp)
    for block in scanner:
        pass  # do something with the block...

Have a look at the blocks documentation to see what they do; also, the examples directory contains some example scripts using the library.

Hacking

Format specification is here:

http://www.winpcap.org/ntar/draft/PCAP-DumpFileFormat.html

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 partecipate in the discussion :)

Pcap-ng write support

Support for writing pcap-ng files is “planned”; that means: I have some ideas on how to write that part and which would be the required changes to the library.

I didn’t add that part (yet) as I currently don’t need it, and I’m wondering whether anybody might (possible use cases are if you’re writing some packet capture tool in Python, or some other kind of capture-file manipulation thing).

If you need this feature, I’d like to hear from you (otherwise, I don’t really think I’m going to invest much time in something that no one needs..).

History

v0.1

  • Support for “scanning” streams of pcap-ng data

  • Support for decoding the “standard” pcap-ng blocks:

    • Section headers

    • Interface description

    • Enhanced packet

    • Simple packet (deprecated)

    • Packet (deprecated)

    • Name resolution

    • Interface statistics

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-pcapng-1.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

python_pcapng-1.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file python-pcapng-1.0.tar.gz.

File metadata

  • Download URL: python-pcapng-1.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5

File hashes

Hashes for python-pcapng-1.0.tar.gz
Algorithm Hash digest
SHA256 03c39a93d083e062630a9d398432f56a04c5513750805127f32162ac45937d0e
MD5 f39ddc1f6d295994a4cf81d0c2403c9f
BLAKE2b-256 86ba5a7f5c5de80ddc396538509cfe628dfdf9054b5873e8f95a763faee96aa4

See more details on using hashes here.

File details

Details for the file python_pcapng-1.0-py3-none-any.whl.

File metadata

  • Download URL: python_pcapng-1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5

File hashes

Hashes for python_pcapng-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ad34fb91d70cf62fbb5c0fbe5565137684fe1f4c9de4abea1811b22043d5976
MD5 55974517a849621cb22e10af5d6a3e10
BLAKE2b-256 9b0fe8aba7e34fd3683fa30092917783c04d8b517fc98f8e46093e8f402c7825

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page