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                    # TCP header
pktfmt udp                    # UDP header
pktfmt ipv4                   # IPv4 header
pktfmt dns                    # DNS header
pktfmt --list                 # Show all 20+ protocols

Custom Inline Format

pktfmt "Type:16,Length:16,Payload:*"

Output:

 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                             ┊
└───────────────────────────────────────────────────────────────┘

Bold Unicode Style

pktfmt tcp --style bold

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, 802.1q, 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.2.0.tar.gz (11.5 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.2.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pktfmt-0.2.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pktfmt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4f924725e15037513fa600d2eceaf907321a89cbc8db0b7967542ddf5db5ac17
MD5 d123a9e71525ebc66626dbe540548494
BLAKE2b-256 d28299f1980abdfcadc7bafe6425e6f598b48d478d081c3aa1ab94275ed9bb86

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pktfmt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pktfmt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9979380c97bef4b39ef01f2bd854c50a16ec7cfd5792d2ab5c635c896052050
MD5 7cf172201c734b07e2fc0216426a5cda
BLAKE2b-256 f5faf4fb87f7a078d6a4eb4d648a727eb78cdd9de476da118ce8668b6b2cb3a6

See more details on using hashes here.

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