• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pure-Python library to parse the pcap-ng format used by newer versions of dumpcap & similar tools.

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.python.org/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:

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 support

Write support exists as of version 2.0.0. See the file examples/generate_pcapng.py for 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:

from pcapng.strictness import Strictness, set_strictness
set_strictness(Strictness.FIX)

Recognized values are Strictness.FORBID (the default), Strictness.FIX (warn about problems, fix if possible), Strictness.WARN (warn only), and Strictness.NONE (no warnings). Circumstances that will result in strictness warnings include:

  • Adding multiples of a non-repeatable option to a block
  • Adding a SPB to a file with more than one interface
  • Writing a PB (PBs are obsolete and not to be used in new files)
  • Writing EPB/SPB/PB/ISB before writing any IDBs

Creating a release

  1. Create a tag for the new version:

    git tag v2.0.0 -m 'Version 2.0.0'
    
  2. Install build dependencies in a virtualenv:

    python -m venv ./.build-venv
    ./.build-venv/bin/python -m pip install build twine
    
  3. Build source and wheel distributions:

    rm -rf ./dist *.egg-info
    ./.build-venv/bin/python -m build
    
  4. Use Twine to upload to pypi:

    twine upload dist/*
    

Troubleshooting

If you get some crazy version number like 2.0.1.dev0+g7bd8575.d20220310 instead of what you expect (eg 2.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.

More Repositories

1

python-libxdo

Python bindings for libxdo
Python
76
star
2

elo

Very simple Python implementation of the Elo rating system.
Python
58
star
3

nicelog

Formatters to nicely display colorful logging output on the console.
Python
19
star
4

pygpgme

A Python binding for the gpgme library, used to drive the gpg command line program.
C
10
star
5

MongoSQL

JSON-based DSLs are not for humans..
Python
10
star
6

yawc

Yet Another Web Chat (Python + GraphQL + Subscriptions experiment)
Python
7
star
7

flask-sqlalchemy-core

SQLAlchemy Core integration for Flask
Python
7
star
8

pycwgen

Python
6
star
9

pyql

GraphQL helpers for Python.
Python
6
star
10

render-tiles

Example Python tile server for PostGIS data
Python
5
star
11

jobcontrol

Job scheduling and tracking library.
Python
4
star
12

PythonScriptBrowser

A simple qt-based browser that runs Python scripts as it would with JavaScript..
Python
4
star
13

jetson-fan-control

NVIDIA Jetson fan control
Python
3
star
14

config-gen

Utility to generate configuration files from templates + context files
Python
3
star
15

CommonScripts

Utility scripts I like to have on all machines..
Python
2
star
16

shared-password-manager

A way to share encrypted files between multiple users, via Git.
Python
2
star
17

ardomino-api

Ardomino Server-side application
Python
2
star
18

apyx

Simple Python-powered Antipixel generation library
Python
2
star
19

blobstore

ZeroRPC-powered general-purpose blobs storage
Python
1
star
20

attendmap

Event attendance map, via Twitter
Python
1
star
21

simplespider

A library to build simple yet powerful spiders, in Python.
Python
1
star
22

contracts

Base library for defining lean "contract" models for Python.
Python
1
star
23

mowaki

Modern Web Application Kit
Python
1
star
24

wiki.hackzine.org

Sources for http://wiki.hackzine.org
Python
1
star
25

ckan-vagrant

Shell
1
star
26

hamradio

Misc helpful scripts for ham radio operation.
Python
1
star
27

patente-nautica

CSS
1
star
28

pickle-attack

Python
1
star
29

harp

Python
1
star
30

spotifyctl

Spotify control script, in Python, via DBus
Python
1
star
31

arduino-iambic-key

Arduino
1
star
32

ham-radio-map

Map showing Ham-radio related stuff, for Ireland.
Python
1
star
33

ObjPack

Object serialization format (JSON superset)
Python
1
star
34

clitools

Tools for creating CLI scripts with Python
Python
1
star
35

Turing

Turing machine implementation in JavaScript
JavaScript
1
star
36

ckan-guerrilla-gear

Guerrilla Gear to try and tame some jungle - Ckan Pack
Python
1
star
37

PyGauges

Utilities for displaying real-time data with Python.
Python
1
star