Skip to main content

Generate RFC-style ASCII packet diagrams from field definitions

Project description

pktfmt

Generate RFC-style ASCII packet diagrams from field definitions.

A modern, pip-installable alternative to protocol that works on Windows and modern Python.

Installation

pip install pktfmt

Features

  • 20+ built-in protocols - TCP, UDP, IP, DNS, and more
  • Custom packet definitions - inline format or JSON files
  • Unicode box drawing - pretty output for modern terminals
  • Variable-length fields - with distinct visual styling
  • Cross-platform - works on Windows, macOS, and Linux
  • Modern Python - supports Python 3.8+

Quick Start

# Show a built-in protocol
pktfmt tcp

# List all available protocols
pktfmt --list

# Custom inline format
pktfmt "Type:16,Length:16,Payload:*"

# Pretty Unicode output
pktfmt udp --unicode

Usage

Built-in Protocols

$ pktfmt tcp
 0                  1                  2                  3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Source Port          |        Destination Port       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Sequence Number                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     Acknowledgment Number                     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Data Of|Reser|      Flags      |          Window Size          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            Checksum           |         Urgent Pointer        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
:                            Options                            :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Custom Inline Format

$ pktfmt "Type:16,Length:16,Payload:*"
 0                  1                  2                  3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|              Type             |             Length            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
:                            Payload                            :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

JSON File Format

pktfmt packet.json
{
  "name": "MyPacket",
  "fields": [
    {"name": "Type", "bits": 16},
    {"name": "Length", "bits": 16},
    {"name": "Payload", "bits": "*"}
  ]
}

Unicode Output

$ pktfmt udp --unicode
 0                  1                  2                  3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│          Source Port                  Destination Port       │
├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│             Length                        Checksum           │
├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
┊                              Data                             ┊
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘

Options

pktfmt <input> [options]

Options:
  -l, --list              List all built-in protocols
  -b, --bits-per-row N    Bits per row (default: 32)
  -s, --style STYLE       Output style: ascii, unicode, bold
  -u, --unicode           Shortcut for --style unicode
  --no-ruler              Omit the bit number header
  -v, --version           Show version

Field Syntax

  • Name:N - Fixed-width field of N bits
  • Name:* - Variable-length field (rendered with : or borders)

Built-in Protocols

Layer Protocols
Layer 2 ethernet, 8021q, arp
Layer 3 ipv4, ipv6, icmp, icmpv6
Layer 4 tcp, udp, sctp
Application dns, dhcp, ntp, tls
Tunneling gre, vxlan, quic
Industrial modbus, dnp3

Why pktfmt?

  • Actually installs via pip - protocol requires manual setup.py installation
  • Works on modern Python - protocol uses deprecated distutils
  • Works on Windows - proper UTF-8 handling
  • Actively maintained - PRs get merged
  • Unicode support - pretty box drawing characters
  • More protocols - 20+ built-in, vs ~10 in protocol

License

MIT

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

pktfmt-0.3.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pktfmt-0.3.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file pktfmt-0.3.1.tar.gz.

File metadata

  • Download URL: pktfmt-0.3.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pktfmt-0.3.1.tar.gz
Algorithm Hash digest
SHA256 fcecbd789a1e9c444a3ad346bdd4b79724f19720600b1471adfd53bf48162968
MD5 cebf187ed1ba7eca0340ab09415344f7
BLAKE2b-256 528eb2fe72b09a6cdc9709459fceb03136ed6121065f7e5aa9bb9a291c88ac24

See more details on using hashes here.

Provenance

The following attestation bundles were made for pktfmt-0.3.1.tar.gz:

Publisher: publish.yml on jordanallred/pktfmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pktfmt-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pktfmt-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pktfmt-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5e04d6d1f542a5e44bdc8d1efa334fe320be5561b0f59719bb11c8a79833f84
MD5 53894993b050f80c3fa33d1c3eb085d4
BLAKE2b-256 d6124895d01d43cd3fb99bdedba6bb8ba492bde1818b5e6d80805f96c6f433d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pktfmt-0.3.1-py3-none-any.whl:

Publisher: publish.yml on jordanallred/pktfmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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