This script is a translation layer that takes standard OpenWrt config files and outputs text that can be passed to Kroki which will then generate an image or pdf, showing network interfaces, subnets and clients. It currently supports both Ethernet and WireGuard interfaces. (Kroki is using nwdiag to generate the image.)
Put NetworkDiagram.py in the same folder as these config files from your OpenWrt device
/etc/config/network
/etc/config/dhcp
Optionally also create a file named "hosts" in the same folder, and populate it in this format
hostname1 IP1
hostname2 IP2
hostname3 IP3
Run the python script
python NetworkDiagram.py
which will output something like tihs
nwdiag{Internet[shape=cloud];Internet -- OpenWrt;
network LAN {
address = "192.168.1.x/24";
OpenWrt [address = "192.168.1.1"];
PC [address = "192.168.1.10"];
Server [address = "192.168.1.25"];
}
network WireGuard_network {
address = "10.0.100.1";
OpenWrt [address = "10.0.100.1"];
Laptop [address = "10.0.100.2"];
Phone [address = "10.0.100.3"];
}
}
This output can be used by Kroki to generate your image. Either directly on kroki.io or by running Kroki locally, for example by using the official Docker image.
The final result will be something like this: