Network Diagram from Live Data
Lesson 8 of 10
The Scenario
Your network diagram is a 3-year-old Visio file that no one has updated. Half the links are wrong. Instead of manually redrawing it, you want to automatically discover the topology from CDP/LLDP and generate an accurate diagram.
The Prompt
Write a Python script that:
1. SSHs into a list of switches from devices.csv using Netmiko
2. Runs "show cdp neighbors detail" on each device
3. Parses the output: local device, local interface, remote device, remote interface, remote IP, platform
4. Builds an adjacency list (no duplicates - if A connects to B, do not also list B connects to A)
5. Generates a network diagram using the graphviz library
6. Output as both a PNG image and a DOT file
7. Label each link with the interface names on both sides
Use ntc-templates to parse CDP output if available.
What AI Gives You
A topology discovery script that crawls your network via CDP and produces a visual diagram. Not Visio-quality, but accurate and automatically generated.
Review and Validate
- CDP must be enabled on all devices for this to work. LLDP is an alternative — ask AI to support both
- Graphviz must be installed separately:
apt install graphvizorbrew install graphviz - The diagram will be rough — use it as a starting point, then clean up in draw.io or Visio
Try It Yourself
Start with a small segment — 5 switches. Verify the discovered topology matches reality before scaling up.
Subscribe to unlock this lesson
₹7,999/year
Full access to all 10 lessons in this course, plus 74 more lab courses, quizzes, and AI mock interviews. 365 days.
Already have an account? Sign in