Wednesday, December 21, 2011

Find Unique Interface Configs on Switches

Recently I needed to find all of the interfaces with non-standard configurations on a bunch of Catalyst 3750 switches. I wrote a simple Python script to automate the process. To run this, save it in a directory with all of the configurations you want to check. Then edit the name.startswith() section near the bottom to match the naming convention for your config files; in my case all of my configs start with "c3750". Then run the script from your CLI:

>python dup_conf.py

If you're on a Mac or Linux system, Python should be installed by default. On Windows, you'll need to install it or run Cygwin. Note that in the default version, the script ignores SVIs and Gigabit interfaces; uncomment the appropriate lines to include them.

The output looks like this:


in config file c3750-1A.txt

interfaces

interface FastEthernet1/0/35

configured like

switchport trunk encapsulation dot1q
switchport trunk native vlan 76
switchport mode trunk
switchport voice vlan 65
no logging event link-status
srr-queue bandwidth share 10 10 60 20
srr-queue bandwidth shape 10 0 0 0
mls qos trust device cisco-phone
mls qos trust dscp
auto qos voip cisco-phone
no mdix auto
spanning-tree portfast

**************************************************
interfaces

interface FastEthernet1/0/11
interface FastEthernet1/0/12

configured like

switchport trunk encapsulation dot1q
switchport trunk native vlan 80
switchport mode trunk
switchport voice vlan 65
srr-queue bandwidth share 10 10 60 20
srr-queue bandwidth shape 10 0 0 0
mls qos trust device cisco-phone
mls qos trust dscp
auto qos voip cisco-phone
no mdix auto
spanning-tree portfast

**************************************************
interfaces

interface FastEthernet1/0/1
interface FastEthernet1/0/2
interface FastEthernet1/0/3
interface FastEthernet1/0/4
interface FastEthernet1/0/5
interface FastEthernet1/0/6
interface FastEthernet1/0/7
interface FastEthernet1/0/8
interface FastEthernet1/0/9
interface FastEthernet1/0/10
interface FastEthernet1/0/13
interface FastEthernet1/0/14
interface FastEthernet1/0/15
interface FastEthernet1/0/16

configured like

switchport access vlan 64
switchport voice vlan 65
srr-queue bandwidth share 10 10 60 20
srr-queue bandwidth shape 10 0 0 0
mls qos trust device cisco-phone
mls qos trust dscp
auto qos voip cisco-phone
no mdix auto
spanning-tree portfast

**************************************************


2 comments:

Mike Donovan said...

You could also substitute something like this, and list the files to check on the command line:

filenames = [sys.argv[1:]]

jswan said...

Yeah, I thought about that but all my files were already named with a consistent pattern so I just embedded it into the script. For anyone who wants to use Mike's suggestion, just remember to add "import sys" at the top.