Skip to main content

Visualize iptables packet flow as Graphviz diagrams

Project description

iptables-graph

Visualize iptables packet flow as Graphviz diagrams. Convert iptables-save output to DOT, SVG, or PNG formats.

Inspired by AChingYo/iptables-graph

PyPI Docker License

Features

  • 📊 Visualize packet flow through all iptables tables (raw, mangle, nat, filter)
  • 🎨 Color-coded tables and chains for easy understanding
  • 🔗 Show custom chains and jump targets
  • 📤 Multiple output formats: DOT, SVG, PNG
  • 🐳 Docker-based (no host dependencies!)
  • 📦 PyPI package (pipx install)

Quick Start

Option 1: Docker (Recommended)

No installation required! Just pull and run:

# Pull from Docker Hub
docker pull sanghaklee/iptables-graph

# Use it
sudo iptables-save | docker run --rm -i sanghaklee/iptables-graph

# Generate SVG
sudo iptables-save | docker run --rm -i sanghaklee/iptables-graph -f svg > graph.svg

# Generate PNG
sudo iptables-save | docker run --rm -i sanghaklee/iptables-graph -f png > example.png

Create an alias for convenience:

# Add to ~/.bashrc or ~/.zshrc
alias iptables-graph='docker run --rm -i sanghaklee/iptables-graph'

# Now use it like a regular command
sudo iptables-save | iptables-graph
sudo iptables-save | iptables-graph -f svg > graph.svg

Option 2: PyPI Package

Install via pip:

pipx install iptables-graph

Use it:

# Generate DOT format
sudo iptables-save | iptables-graph > graph.dot

# Generate SVG (requires graphviz installed)
sudo iptables-save | iptables-graph -f svg > graph.svg

# Generate PNG (requires graphviz installed)
sudo iptables-save | iptables-graph -f png > example.png

Note: For SVG/PNG conversion, you need to install graphviz:

# Debian/Ubuntu
sudo apt-get install graphviz

# RHEL/CentOS
sudo yum install graphviz

# macOS
brew install graphviz

Usage

Basic DOT Output

sudo iptables-save | iptables-graph

Output:

digraph {
    graph [pad="0.5", nodesep="0.5", ranksep="2"];
    node [shape=plain]
    rankdir=LR;
    ...
}

Generate SVG Diagram

sudo iptables-save | iptables-graph -f svg > graph.svg

Generate PNG Image

sudo iptables-save | iptables-graph -f png > example.png

Read from File

# Save iptables rules to file
sudo iptables-save > rules.txt

# Generate diagram
cat rules.txt | iptables-graph -f svg > diagram.svg

Using with Docker Volumes

# For file input/output with Docker
docker run --rm sanghaklee/iptables-graph \
  -v $(pwd):/data
  -i /data/iptables-save.txt 
  -f svg 
  -o /data/diagram.svg

Command Line Options

usage: iptables-graph [-h] [-i INPUT] [-o OUTPUT] [-f {dot,svg,png}]

iptables-save output → Graphviz converter (dot/svg/png)

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        Input file (default: stdin)
  -o OUTPUT, --output OUTPUT
                        Output file (default: stdout)
  -f {dot,svg,png}, --format {dot,svg,png}
                        Output format: dot (default), svg, or png

Example Output

example.png

Color Scheme

  • 🔴 raw table: Red (#FA7070)
  • 🔵 mangle table: Blue (#AEE2FF)
  • 🟣 nat table: Purple (#E5D1FA)
  • 🟢 filter table: Green (#BEF0CB)

How It Works

  1. Parse iptables-save output to extract rules, chains, and policies
  2. Generate Graphviz DOT format with color-coded tables
  3. Convert (optional) to SVG or PNG using graphviz

Requirements

Docker Method

  • Docker only

PyPI Method

  • Python 3.7+
  • Graphviz (optional, for SVG/PNG conversion)

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for development setup, building, and release process.

License

MIT License

Links

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

iptables_graph-1.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

iptables_graph-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file iptables_graph-1.0.0.tar.gz.

File metadata

  • Download URL: iptables_graph-1.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for iptables_graph-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d8659345a5ddf6af5be67d215827f2943887b2df7a3bc1bf265e672c9a687958
MD5 7320b417cb3ae09ee4a9e85a1fcc884d
BLAKE2b-256 6d03814f31de10833fe96a4743bd8f4750bd88e08c38fae855ae85f2831913f9

See more details on using hashes here.

File details

Details for the file iptables_graph-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: iptables_graph-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for iptables_graph-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 66ffbbd8c088a2d0ea4a651cd40cba3b3883a6f525efb578da09044496a2868d
MD5 80d35cb9ed5034527a3dfdbf97e5fef9
BLAKE2b-256 bc1a72a4506fb6c7aafe6be49ecb4163d210754f2ebcfc6f02fa0700f036f83d

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