Thursday, 30 July 2009

SNMP for CDP Trawling of Cisco devices

The SNMP voyage continued today with a script to discover CDP neighbours via SNMP and then go get their CDP neighbour info and so on (although not too far!). Basically an intelligent network mapping. Couldn't do this via expect or anything due to a SecID front end on logins to the devices, so had to drop back to SNMP.

Obviously all Cisco based stuff, specifically switches but it's fairly generic.

Key things here are the SNMP IDs for the useful information:
1.3.6.1.4.1.9.2.1.3: Device name
1.3.6.1.2.1.47.1.1.1.1.13.1: Model number

To actually get the rest of the CDP data, it all gets a bit messy. Firstly you need the CDP table. This is started with a dump of IDs to uniquely identify each table entry. These can be obtained with an SNMP get of the following ID:

1.3.6.1.4.1.9.9.23.1.2.1.1.3

The bit you need is the last two numbers - The first number represents the local port ID (as a number) and the second represents a unique ID that we can use to get more info.

So once we have these (lets call them our_port and table_ID) we can use:

1.3.6.1.2.1.2.2.1.2.our_port
to get the local port name

and then for your cdp info:
1.3.6.1.4.1.9.9.23.1.2.1.1.4.table_id to get IP address (in hex)
1.3.6.1.4.1.9.9.23.1.2.1.1.6.table_id to get Name
1.3.6.1.4.1.9.9.23.1.2.1.1.7.table_id to get Remote port
1.3.6.1.4.1.9.9.23.1.2.1.1.8.table_id to get Device type

There is other stuff too - best take a look at the SNMP browser on Cisco for more info (see link in previous post).