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.

Share/Save/Bookmark


Posted by Anonymous (66.74.xx.xx) on Thu 7 May 2009 at 05:04
Oh yes. I'm just getting my CCNA and this looks like a promising command. Now all I need is a real switch to play with.

[ Parent | Reply to this comment ]

Posted by endecotp (86.6.xx.xx) on Sun 10 May 2009 at 00:02
[ Send Message | View Weblogs ]
I understand this is a CISCO proprietary protocol. My little HP switch seems to send out LLDP packets - I've seen them in wireshark while debugging other things - and Wikipedia tells me that's the vendor-neutral equivalent. So is there a similar utility for LLDP? (Not that I have any need for it - my network is simple enough that I can normally see both ends of the wire at the same time, and I haven't run out of colours yet!)

[ Parent | Reply to this comment ]

Posted by djzort (114.76.xx.xx) on Sun 10 May 2009 at 01:25
[ Send Message ]

apt-get install lldpd

"lldpd also implements CDP (Cisco Discovery Protocol), FDP (Foundry Discovery Protocol), SONMP (Nortel Discovery Protocol) and EDP (Extreme Discovery Protocol)"

homepage https://trac.luffy.cx/lldpd/

http://www.fragfest.com.au

[ Parent | Reply to this comment ]

Posted by stsimb (193.92.xx.xx) on Tue 12 May 2009 at 14:02
[ Send Message ]
Wouldn't it be nice if we also had a small cdp server on our linux boxes, advertising its hostname and capabilities?

Thus, we could issue "show cdp neighbors" on a cisco switch, and have a fully up-to-date diagram of our LAN, no need to update descriptions etc ..

[ Parent | Reply to this comment ]

Posted by stsimb (193.92.xx.xx) on Tue 12 May 2009 at 14:36
[ Send Message ]
to answer my own question.. cdp-send of cdp-tools does just that! great!!

[ Parent | Reply to this comment ]

Posted by djzort (203.10.xx.xx) on Mon 18 May 2009 at 01:31
[ Send Message ]

cdp-tools isnt available on my squeeze box?...

in any case people might want to try lddpd

run "lldpd -c"

that will fire it up with CDP support. cdp

http://www.fragfest.com.au

[ Parent | Reply to this comment ]

Posted by stsimb (193.92.xx.xx) on Mon 18 May 2009 at 12:47
[ Send Message ]
I found ladvd better, because it works with bonding interfaces .. http://blinkenlights.nl/software/ladvd/

[ Parent | Reply to this comment ]

Posted by Anonymous (71.105.xx.xx) on Sun 19 Jul 2009 at 11:05
WOW, now that I am a CCNA going for my Linux+ I will have to give it a try.

[ Parent | Reply to this comment ]

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search