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

I'm using Net::SNMP to pull Bridge table information from a number of managable switches. For the most part, everything works just fine. The problem is that some number of hardware addresses do not come through correctly (maybe 1 in a 100). My guess there is a translation issue where the hardware address is somehow being converted to a different format before it is displayed.

I have used Data::Dumper to view the returning information, and the error is there. I have used the translate() option of Net::SNMP and it only makes things worse. Also, the shell version of snmpwalk does not exhibit the problem at all! (But of course I would rather use perl modules rather than system calls.)

Again, most hardware addresses come through fine, but one example:
'000d56385734' is displayed as '^@^MV8W4'

And I can't find a relationship between the real address and the output - assuming there is one. Also, I get the same results from both the layer 2 switch the node is plugged in to, and the layer 3 core switch in the network - different manufacturers.

Following is a stripped down version of the code I am using (the final output is just a list of mac addresses that the switch knows about):

#!/usr/bin/perl use strict; use Net::SNMP; my ( $key ); my $session = Net::SNMP->session(Hostname => '1.2.3.4', Community => 'public'); print $session->error(); my $macoid = '1.3.6.1.2.1.17.4.3.1.1'; my $macref = $session->get_table($macoid); foreach $key (keys %{$macref}) { print "$macref->{$key} \n"; }
TIA John

Replies are listed 'Best First'.
Re: Net::SNMP and Mac Addresses
by atcroft (Abbot) on Apr 07, 2004 at 20:18 UTC

    I mentioned your post to a coworker, who had mentioned a similar experience recently. My coworker filed a bug on the issue, which the module's author denoted as a duplicate, referring him to the notes on bug report #1946, located at http://rt.cpan.org/NoAuth/Bug.html?id=1946. Not sure that is the answer you were expecting, but hope it helps....

Re: Net::SNMP and Mac Addresses
by Anonymous Monk on Apr 08, 2004 at 02:43 UTC

    the bug mentioned sounds right on target. the reason the snmpwalk command works is because it is using the (net|ucd)-snmp libraries (most likely anyways).

    IMHO, if you want much better SNMP handling switch to the SNMP module that comes with the (ucd|net)-snmp libraries.

    the SNMP module can use your MIB files to determine the correct format to return the data from the device. it also tends to be much faster when you have lot's of stuff to fetch, and much easier to get working with SNMPv3.

Re: Net::SNMP and Mac Addresses
by jds (Acolyte) on Apr 13, 2004 at 18:40 UTC
    Thanks to those that responded! After following through with the bug report (which was down for a while!), I came up with a workable solution to the original code:
    #!/usr/bin/perl use strict; use Net::SNMP; my ( $key ); my $session = Net::SNMP->session(-hostname => '1.2.3.4', -community => 'public', -translate => [-octetstring => 0x0], ); print $session->error(); my $macoid = '1.3.6.1.2.1.17.4.3.1.1'; my $macref = $session->get_table($macoid); foreach $key (keys %{$macref}) { print unpack('H12', $macref->{$key}) ."\n"; }
      I've been struggling with this for the last few days, but I wasn't seeing anybody else mentioning this anywhere. This was a big help! Thanks.
      It worked. What a wonderful help! Thanks!