Where art thou? - CDPR

Posted by djzort on Wed 6 May 2009 at 11:30

cdpr is a nifty little command which speaks the Cisco Discovery Protocol, allowing you to learn interesting things from your network.

Installing the cdpr package is simple, and done in the usual manner:

root@optimus:/home/dean#apt-get install cdpr

Once installed you may view the help by running "cdpr -help" (Note that the script is installed in /sbin, and will most likely only be in the PATH for root)

root@optimus:/home/dean# cdpr -help
cdpr - Cisco Discovery Protocol Reporter
Version 2.2.1
Copyright © 2002-2006 - MonkeyMental.com

d: Specify device to use (eth0, hme0, etc.)
h: Print this usage
t: time in seconds to abort waiting for a packet (should be > 60) v[vv]: Set verbose mode ** Options dealing with server updates: ** u: Send cdpr information to a cdpr server requires config file as arg l: Location/description of this port for use with -u or -s and -p n: Override the hostname reported to the server for use with -u or -s and -p s: Server to send information to specify port with a : after Server/IP Example: 192.168.1.20:88 (default: 80) requires -p (overridden by -u) p: Path of server script to send data to requires -s (overridden by -u)

Running cdpr with no options gives a simple menu, allowing you to select an interface to work with.

root@optimus:/home/dean# cdpr
cdpr - Cisco Discovery Protocol Reporter
Version 2.2.1
Copyright © 2002-2006 - MonkeyMental.com

1. eth0 (No description available
2. br0 (No description available)
3. eth1 (No description available)
4. usb1 (USB bus number 1)
5. usb2 (USB bus number 2)
6. usb3 (USB bus number 3)
7. usb4 (USB bus number 4)
8. usb5 (USB bus number 5)
9. any (Pseudo-device that captures on all interfaces)
10. lo (No description available)
Enter the interface number (1-10):

Select your preferred interface and wait patiently as cdpr does its magic.

8. usb5 (USB bus number 5)
9. any (Pseudo-device that captures on all interfaces)
10. lo (No description available)
Enter the interface number (1-10):1
Using Device: eth0
Waiting for CDP advertisement:
(default config is to transmit CDP packets every 60 seconds)
Device ID
  value:  SMC10390011
Addresses
  value:  10.16.126.9
Port ID
  value:  4/33

Tada! Switch and switch port. Nifty. That was much easier than playing the cable chase through messy data cabinets game, or the always fun watch-switch-lights-while-friend-unplugs-and-plugs-over-the-phone game!

Now CDP gives much more info that than. Much much more!

If you look at the output of "cdpr --help" or the cdpr man page you'll see you can skip the annoying menu and specify the device using -d, and you can also turn up the verbosity with -v or -vvv

root@optimus:/home/dean# cdpr -d eth0 -vvv
cdpr - Cisco Discovery Protocol Reporter
Version 2.2.1
Copyright © 2002-2006 - MonkeyMental.com

Using Device: br0
Waiting for CDP advertisement:
(default config is to transmit CDP packets every 60 seconds)
Received a CDP packet, header length: 484

cdp packet:
  version:      02
  time to live: b4
  checksum:     83e2

cdp type/len/val:

[snip]

cdp type/len/val:
  type:   001a - Unknown type
  length: 0010
Unknown type
  value:  00 00 00 01 00 00 00 00 FF FF FF FF
Data Link Type: Ethernet (10MB, 100MB, 1000MB and up).

cdpr also allows you to use the -u command to send these details off to a web server. Look at the /usr/share/doc/cdpr/README.cdprs file for how to do this. Implementation of the server is left up to the user, however the data is just sent via get.

cdpr can also easily be wrapped with a little perl/python/poisonoftheday and the data used for other accounting purposes. We use it as part of our self inventory system, which emails the details off to our inventory db on each boot. With a little coding and some good racking standards, much of the machines location can then be derived from which switch and switch port the machine is plugged in to1. With IPMI many other details (like serial number) can also be bundled in there, making inventory almost completely automated.

Enjoy!

[1] by convention, we plug the serial console for the servers into the same port #1 on the serial servers as we do on the ethernet switch. We also We also assume that servers are in the same rack as the switch and serial console. This makes inventory extremely easy and highly accurate. It also means servers can be relocated and inventory updated automatically, giving us more time for foosball.


This article can be found online at the Debian Administration website at the following bookmarkable URL (along with associated comments):

This article is copyright 2009 djzort - please ask for permission to republish or translate.