NetMap CLI is a Python tool that generates network topology diagrams and graph data files from a simple CSV input. It's designed to quickly visualize device connectivity.
- CSV Input: Reads network links from a CSV file with 'SourceDevice' and 'TargetDevice' columns.
- Graph Visualization: Generates a PNG image of the network map using
matplotlibandnetworkx.- Supports multiple layout algorithms:
spring(default),kamada_kawai,circular,random,shell,spectral.
- Supports multiple layout algorithms:
- Graph Data Export: Can export the network graph to:
- GEXF format (for use in Gephi or other graph analysis tools).
- GraphML format (another common format for graph tools).
- Command-Line Interface: Easy-to-use CLI for specifying input and output options.
- Python 3.6+
- Libraries:
networkx,matplotlib,scipy(SciPy is a dependency for somenetworkxlayout algorithms).
-
Clone the repository or download the files. Ensure you have the
netmap_tooldirectory (containingmain.py,mapper.py,__init__.py) and therequirements.txtfile. -
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies: Navigate to the directory containing
requirements.txtand run:pip install -r requirements.txt
The tool is run from the command line using python -m netmap_tool.main.
--input_csv INPUT_CSV: (Required) Path to the input CSV file.- The CSV file must contain 'SourceDevice' and 'TargetDevice' headers.
- Each row defines a link between the two specified devices.
--output_png OUTPUT_PNG: (Optional) Path to save the output PNG image (e.g.,mymap.png).--layout {spring,kamada_kawai,circular,random,shell,spectral}: (Optional) Layout algorithm for the PNG map. Defaults tospring.--output_gexf OUTPUT_GEXF: (Optional) Path to save the graph in GEXF format (e.g.,mymap.gexf).--output_graphml OUTPUT_GRAPHML: (Optional) Path to save the graph in GraphML format (e.g.,mymap.graphml).-h, --help: Show help message and exit.
-
Generate a PNG map with the default spring layout:
python -m netmap_tool.main --input_csv path/to/your/links.csv --output_png network_diagram.png
-
Generate a PNG map with the Kamada-Kawai layout:
python -m netmap_tool.main --input_csv links.csv --output_png map_kk.png --layout kamada_kawai
-
Export the graph to GEXF format:
python -m netmap_tool.main --input_csv links.csv --output_gexf my_network.gexf
-
Generate a PNG and also export to GraphML:
python -m netmap_tool.main --input_csv links.csv --output_png visual_map.png --output_graphml data_map.graphml
-
Only build the graph and print info (no file output):
python -m netmap_tool.main --input_csv links.csv
(The tool will inform you that no output options were specified)
Your input CSV file must have a header row with SourceDevice and TargetDevice.
Example links.csv:
SourceDevice,TargetDevice
RouterA,Switch1
RouterB,Switch1
RouterA,RouterB
Firewall,RouterA
Switch1,ServerX.
├── netmap_tool/
│ ├── __init__.py # Makes 'netmap_tool' a Python package
│ ├── main.py # CLI entry point
│ └── mapper.py # Core logic for graph building, drawing, and exporting
├── requirements.txt # Python dependencies
└── README_netmap.md # This documentation file
- Simplicity: This tool is designed for simple, direct device-to-device connectivity visualization. It does not parse complex configurations or infer relationships beyond what's explicitly in the CSV.
- Layouts: Graph layout can be challenging for large or complex networks. The default layouts are good for small to medium-sized graphs. For very large networks, using the GEXF/GraphML export with a dedicated tool like Gephi is recommended for better layout control and exploration.
- No Device Details: The map does not include interface names, IP addresses, VLANs, or other detailed device information. It only shows device names and their connections.
- Error Handling: Basic error handling for file operations and CSV parsing is included. More complex CSV issues might require manual data cleaning.
- Support for other input formats (e.g., JSON, YAML).
- Ability to add attributes to nodes/edges via CSV (e.g., device type, link speed) and visualize them.
- More sophisticated layout options or interactivity (would likely require different libraries e.g., web-based).
- Basic parsing of simplified device configuration snippets (e.g.,
show cdp neighboroutput).