Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Do you want to listen to the cdp information that is flowing on the network or extract the cdp info from the devices you discover.
If the former, all you'll see is the data from your local switch or router. Your question sounds like you are looking for the latter.
If the latter, I've attached a perl program that I used in a prior job that would collect all of the cdp info so that I could create a network topology in a modeling program. (Rename the file to remove the .txt suffix that was required for upload.)
I can't find the original source code from the original author, but this modified copy worked quite well for me.
The one caveat is that the Cisco devices may be set up to restrict access to cdp data. My former employer's audit department had instructed the network engineers to do just that. I left just in time.
If you can't get to the cdp mibs with a "mib walker" you won't be able to get them with this perl program.
hope this helps.
Last edited by tommylovell; 01-25-2011 at 02:15 PM.
To get this to work, i had to go to the /usr/lib/perl5/ directory and search for Util.pm, copy it to /home/trlove/modules, and also SNMP.pm to /home/trlove/modules
The error previous to that was:
Quote:
Can't locate SNMP_util.pm in @INC (@INC contains: /home/trlove/modules /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at ./cdp.pl line 45.
cd /; find . -name SNMP_util.pm - Returns nothing.
/usr/lib/perl5/site_perl/5.8.8/SNMP/Util.pm seems close, but the script doesn't seem to be looking for this filename
Now i have the modules sorted out, but am getting this error:
Quote:
/cdp.pl
"my" variable $value masks earlier declaration in same statement at /home/trlove/modules/SNMP_util.pm line 804.
"my" variable @oid_names masks earlier declaration in same statement at /home/trlove/modules/SNMP_util.pm line 1636.
Name "SNMP_Session::suppress_warnings" used only once: possible typo at ./cdp.pl line 56.
[Warning] No configuration file or incorrect file name, use default
End of discovery run.
---------- Statistics Information ----------
CDP capable discovered: 0
non-CDP capable discovered: 0
Time elapsed: 0.070
Last edited by szboardstretcher; 01-25-2011 at 03:02 PM.
Oops. Sorry. Remove that line. That was where I downloaded required module to, from CPAN. (I didn't have any authority to install modules into the standard Perl location, as I was just an unprivileged user.)
I think the three modules that are needed, BER.pm, SNMP_Session.pm and SNMP_util.pm, all came from CPAN.org.
I guess a comment in package POE::Component::SNMP::Session says it best
Quote:
NOTE: the Perl support for net-snmp is NOT installable via CPAN. On
most linux distros, it is usually available as a companion package to
net-snmp. ...
When I originally ran this years ago I could not install in the libraries in the @INC path so that is why I had to use 'use lib' and a private library, "/home/trlove/modules". That 'use lib' should be unnecessary.
I found on my Fedora 14 system that if I did a 'yum install net-snmp-perl' (not certain if this is needed); a 'yum install perl-Net-SNMP'; and a 'yum install perl-SNMP_Session', I could run cdp.pl and get the same results as you.
Code:
[root@athlon ~]# ./cdp.pl
"my" variable $value masks earlier declaration in same statement at /usr/local/share/perl5/SNMP/Util.pm line 804.
"my" variable @oid_names masks earlier declaration in same statement at /usr/local/share/perl5/SNMP/Util.pm line 1636.
Name "SNMP_Session::suppress_warnings" used only once: possible typo at ./cdp.pl line 57.
[Warning] No configuration file or incorrect file name, use default
End of discovery run.
---------- Statistics Information ----------
CDP capable discovered: 0
non-CDP capable discovered: 0
Time elapsed: 0.160
[root@athlon ~]#
The first three lines of output are probably because the underlying modules have changed since this was written. I'll need to look into this. (Or maybe some Perl guru will see this and say what is going wrong.)
The fourth line, "[Warning] No configuration file or incorrect file name, use default" is emitted from the subroutine initConf (near line 522).
It's saying that there isn't a config file. By default it is '/etc/cdp_conf.txt' or 'cdp_conf.txt' in your current directory.
When I add that file to my current directory and seed it with a starting ip address of 192.168.1.1, I get one step further and then it bombs.
Code:
[root@athlon ~]# ./cdp.pl
"my" variable $value masks earlier declaration in same statement at /usr/local/share/perl5/SNMP/Util.pm line 804.
"my" variable @oid_names masks earlier declaration in same statement at /usr/local/share/perl5/SNMP/Util.pm line 1636.
Name "SNMP_Session::suppress_warnings" used only once: possible typo at ./cdp.pl line 57.
[0 main] Processing: 192.168.1.1
Undefined subroutine &main::snmpget called at ./cdp.pl line 291.
[root@athlon ~]#
I yum installed 'perl-POE-Component-SNMP' (and its 20 dependencies) thinking that this might make a difference. Same results.
I'll look at this further in the morning. It's past midnight and my brain is shutting down.
btw, I don't have any Cisco gear at home, so I can only test this so far, but hopefully I can at least get it to run cleanly.
Last edited by tommylovell; 01-25-2011 at 11:19 PM.
I commented out each of the duplicated lines, so now it runs cleanly but there is nothing to discover in my home network.
I loaded up the cdp_conf.txt file with non Cisco IP addresses,
[root@athlon ~]# ./cdp.pl
[0 main] Processing: 192.168.1.1
[openSNMPSession] Failed to connect to 192.168.1.1
openSNMPSession failed: IP=192.168.1.1
[0 main] Processing: 192.168.1.50
PRINT SERVER PS-6E2DF2
[cdp_fetch] ip=192.168.1.50
[cdp_fetch] can not retrieve cdp from this host
[0 main] fetchCDP failed: 192.168.1.50; putting in retry list
[1 main] Processing: 192.168.1.51
[openSNMPSession] Failed to connect to 192.168.1.51
openSNMPSession failed: IP=192.168.1.51
[1 main] Processing: 192.168.1.93
[openSNMPSession] Failed to connect to 192.168.1.93
openSNMPSession failed: IP=192.168.1.93
[1 main] Processing: 192.168.1.94
[openSNMPSession] Failed to connect to 192.168.1.94
openSNMPSession failed: IP=192.168.1.94
[1 main] Processing: 192.168.1.103
[openSNMPSession] Failed to connect to 192.168.1.103
openSNMPSession failed: IP=192.168.1.103
End of discovery run.
---------- Statistics Information ----------
CDP capable discovered: 1
non-CDP capable discovered: 5
Time elapsed: 0.140
[root@athlon ~]#
[root@athlon ~]#
Oddly enough, it thinks my print server is cdp capable...
I can't run it in work. I'm a Linux engineer and this would really exceed my job function and probably would be viewed as a hacking/intrusion attempt... There is zero tolerance for experimentation if it's outside of our job function, i.e. grounds for termination.
Have you seeded it with a starting Cisco device IP address and gotten it to discover other Cisco devices?
I was trying to query CDP info on a low spec netbook today and came across this post.
The perl solutions elsewhere in this thread were a bit complex/heavy for my situation, but I found this: https://github.com/yurividal/tuxCDP/
You only need to have tcpdump and awk installed - worked great for me (and the coloured text output was a nice touch).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.