HowTo get CDP neighbor information through Python and SNMP

This new script is for Network Engineers and System Engineers a like. Though I must admit it is more for the System Engineers who do not have access to the command line on the CDP enabled device. Have you ever wanted to know what CDP enabled devces ( and info related to those devices ) that were directly connected to your your Core Switch? But you just do not have the access to get that info. But you do have access to the monitoring system, which has SNMP access to the Core Switch.

Well this is where my script comes into play... Stay tuned for updates, as I'm planning on adding to this script. So you can run it with the detail option and a detail port option. Please post any support related question in the forums here..http://www.linuxdynasty.org/forums/Scripting/scripting/sh_cdp_neighbor_help

Revision 1.2 9/13/2009
  • Catch all CDP connected switches, even if there is more then 1 switch seen through 1 port.

Revision 1.1 9/11/2009

  • Added –type option ( –type=detail )
Revision 1.0 9/10/2009
  • This script is the equivalent of sho cdp nei on a cisco switch, but this is using snmp.

Now this is how it will look if you run sh_cdp_neighbor.py script…

As you can see I was able to get about 99% of what the command line version of show cdp neighbor was able to retrieve.
Here is another example of the newest feature…..

As you can see I was able to get about 99% of what the command line version of show cdp neighbor detail was able to retrieve.

You will need the two python modules to run this script. which are pysnmp and pyasn1.
To make your life easier you should do the following…
  1. install python-setuptools
  2. then run easy_install pysnmp
  3. and easy_install pyasn1
  4. or you can download the 2 modules manually.
    pysnmp and pyasn1
  5. then unzip the 2 files and in each directory run python setup.py install

I am using the following revisions from the python cheese shop pysnmp 4.1.7a and pyasn1 0.0.6

You can download the script here… sho_cdp_neighbor.py
Download

This entry was posted in Cisco, Python, SNMP and tagged , . Bookmark the permalink.

One Response to HowTo get CDP neighbor information through Python and SNMP

  1. mfieldhouse says:

    Hey again, I’ve just been looking through all your Python projects after searching for a Python switchport discovery tool. This also looks like a great tool that I’d like to use.

Leave a Reply