Python script, converts Cisco CDP output to csv output
Download python script here: cdp2csv_stdout
# This script takes the output of Cisco's "show cdp neighbors" and # converts it to a csv formatted output. # # Usage: # # This script assumes the devices name is located in the first part of # the filename. i.e. [device_name].[fqdn].[extension] # # There are two parts to this script; # 1) Load the cdp_nei file and parse through it. # Sometimes data is split in two lines, sometimes it's all on one. # So we loop through the file, find what we think is valuable, and # put all data for one neighbor on a single line. # 2) Loop through the lines of data, pull out the individual parts of # data elements, print in csv format. $cdp2csv_stdout.py -h usage: cdp2csv_stdout.py [-h] [-c] [-n LOCAL_DEV_NAME] [-dv DEBUG_LEVEL] filename This script converts the results of 'show cdp neighbor' and turns it into csv output. CSV data is sent to stdout, so redirect or pipe as needed. positional arguments: filename The name of the file which contains the output of 'show cdp neighbor' optional arguments: -h, --help show this help message and exit -c Seperate data elements by a comma (',') rather than a tab. Tab is default. -n LOCAL_DEV_NAME Set the local hostname. If this flag is NOT set we assume the first part of the filename is the local node name. -dv DEBUG_LEVEL Turn on debug verbosity level. '0' is off (default). This will invalidate the CSV output structure, but is useful for troubleshooting.