Python parser script

We can now use a Python script to parse the LLDP neighbor output from each device and construct a network topology graph from the results. The purpose is to automatically check the device to see whether any of the LLDP neighbors have disappeared due to link failure or other issues. Let's take a look at the file and see how that is done.

We start with the necessary imports of the packages: an empty list that we will populate with tuples of node relationships. We also know that Gi0/0 on the devices are connected to the management network; therefore, we are only searching for Gi0/[1234] as our regular expression pattern in the show LLDP neighbors output:

import glob, refrom graphviz import Digraph, Source ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.