jdwindle

networks and infrastructure . spokane, wa

::.2026.10.08 . writing

First Useful Netmiko Script: VLAN Audit

I got tired of SSHing into two switches to compare show vlan brief. You can pull both at once with a small Netmiko loop:

from netmiko import ConnectHandler

devices = [
  {"host": "192.168.99.11", "device_type": "cisco_ios", "username": "admin"},
  {"host": "192.168.99.12", "device_type": "cisco_ios", "username": "admin"},
]

for d in devices:
    conn = ConnectHandler(**d)
    print(f"== {d['host']} ==")
    print(conn.send_command("show vlan brief"))

Notes

  • send_command blocks. You wait for each device in turn. That works for two switches and it drags for fifty.
  • Do not hardcode passwords. Use getpass or env vars.
  • Pipe the outputs through difflib and you get an audit you can save and share.

Repo: the cleaned script is still on the bench with the net-scripts project; I will publish it when that bay is ready.

Recap

  • Problem: Comparing show vlan brief across switches by hand is slow and the output is hard to save or diff.
  • Design: A short Netmiko loop pulls the command from each device; credentials from env vars; output saved and diffed with difflib.
  • Build: Under 20 lines of Python; optional TextFSM parsing for structured rows.
  • Tradeoffs: send_command is sequential and slow at scale; Netmiko enforces nothing.
  • Results: ~1 hour of manual auditing reduced to a few minutes; output is git-diffable.
  • Reproduce: Lab switches with sample VLANs; secrets via environment variables.
  • Takeaway: Netmiko is the right tool for “what is the network right now?”