Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to print out a list of mac addresses from a cisco switch using the SNMP_util module that came with Simon Leinen's perl 5 modules: SNMP_Session.pm and BER.pm in SNMP_Session-1.06.tar.gz located at: http://www.switch.ch/misc/leinen/snmp/perl

The script (below) works except that a few of the mac addresses that are printed out are missing the last part (last 2 hex digits or last 4 hex digits). I used snmpwalk from net-snmp.org to confirm what the rest of the mac address should be in the cases where the mac address was truncated. In all cases, the next two characters of the mac address that should have been printed out are "a3". I just started learning perl so I hope the cause is some simple oversight on my part. By the way, some mac addresses that were printed out correctly did contain "a3". Any ideas on what the cause of the problem is and how to fix or debug? Thanks. The machine the code is running on is a Sparc with SunOS 5.8 with perl version 5.005_03 built for sun4-solaris.
#! /usr/bin/perl -w use lib '/path/to/modules'; use SNMP_util; use strict; &snmpLoad_OID_Cache("/path/to/file/with/oids"); # community string indexing my $community = 'community@1'; my $version = "2"; my $host = "192.168.1.1"; my $host_options = "$community" . "@" . "$host" . ":::::2"; my @results = &snmpwalk($host_options, "dot1dTpFdbAddress"); my ($result, $oid, @macs, $mac); foreach $result (@results) { ($oid, $result) = split(/\:/, $result); } foreach $result (@results) { $result = unpack("H*", $result); } foreach $result (@results) { print "$result\n"; } Example Output: 00065ecb6b36 00065ecb6b 00065ecb6b3d The second mac address in the list above is missing the last two hex d +igits which according to snmpwalk from net-snmp.org should be "a3".

Replies are listed 'Best First'.
Re: SNMP_util truncated mac addresses
by ikegami (Patriarch) on Oct 09, 2004 at 20:42 UTC
    Setting @results to 'oid:' . chr(0x00).chr(0x06).chr(0x5e).chr(0xcb).chr(0x6b).chr(0xa3) prints 00065ecb6ba3. So it seems snmpwalk (or something it uses) 1) cannot handle that char, or 2) does not return what you think it does (which is unlikely since it worked for the other two). I find it really odd that a non-strigyfied number is returned in a ':' seperated string. Are you able to get the address returned as a string instead of as a number?
Re: SNMP_util truncated mac addresses
by Anonymous Monk on Oct 10, 2004 at 01:10 UTC
    since you have net-snmp you should just use their module. that way, if the command line tools work then the module will work (since it uses the same library). i've used the net-snmp (ucd-snmp) module for many years now to query thousands of devices and have never run into such funkyness as you're seeing.
      Thanks for the suggestion. From what I read online you can do more with the net-snmp perl module. I think I managed to install the perl modules that go with net-snmp5.1.1. I can type "use SNMP;" in a perl file and perl does not complain about not finding the module. However, the readme files do not clearly explain to me the functions I can call (and with what arguments), and what is returned. Does anybody know of a good document that lists the functions, arguments, tells/shows what is returned by the functions. I have hunted on Google but have yet to find a good document showing the syntax and how to use the functions in the perl module. Thanks.