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-0.1.0.tar.gz (7.2 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-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for iptables_graph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bef37fac33e3010246cfc0e625b6170fb0d5c28f6cb2a335c290aeec4fad8a65
MD5 6db0453321cd39ae16004eacafcc0a2a
BLAKE2b-256 0fbbc660a8e39b4a3ad1ee3ca8eb3a2e55c95e064061156a5a5ac6cbd92bef71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iptables_graph-0.1.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-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b95b66af12756191e7f12d5350e051baf0bdc984dde7ee2829fc7daed3deb53b
MD5 96b0bc83359575de63d1259bbe0b500d
BLAKE2b-256 1b0a1770e5cbd7a3a216c57af0245bc3eb9dfc4078132828958299ee1aea9637

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