Greetings o guides to wisdom

I am starting out with Net::SNMP. I am trying to query a switch's switching table. This goes OK, except it appears that Net::SNMP is garbling a couple of the MAC addresses when processing the result of the queries.

This is the fragment of code in question:

#!/usr/bin/perl use strict; use Net::SNMP qw(snmp_dispatcher oid_lex_sort); my $host = '3c39t1-01'; my $raw; my $key; my $value; my %macTable; my $TpFdbAddress = '1.3.6.1.2.1.17.4.3.1.1'; my $result; my ($session, $error) = Net::SNMP->session( -hostname => $ARGV[0] || $host, -community => $ARGV[1] || 'public', -port => $ARGV[2] || 161 ); if (!defined($session)) { printf("ERROR: %s\n", $error); exit 1; } if (defined($result = $session->get_table(-baseoid => $TpFdbAddress))) { foreach (oid_lex_sort(keys(%{$result}))) { $raw = $_; $value = $result->{$_}; $raw =~ s/$TpFdbAddress.//; $macTable{$raw} = $value; } } else { printf("ERROR: %s\n\n", $session->error()); } $session->close; foreach $key (sort(keys(%macTable))) { print "$key -> $macTable{$key}\n"; } exit 0;
Running it results in output like this:
[snip] 0.13.162.0.144.140 -> 0x000da200908c 0.13.86.118.96.80 -> ^@^MVv`P 0.13.86.171.103.33 -> 0x000d56ab6721 0.13.86.178.142.133 -> 0x000d56b28e85 0.13.86.225.88.22 -> 0x000d56e15816 0.13.86.32.12.60 -> ^@^MV ^L< 0.14.12.99.128.216 -> 0x000e0c6380d8 [snip]
As you can see, the "value" for a couple of the keys is garbled. These values are always garbled when the script runs, and the values are always garbled even when the same key and value results from a query on a different switch. This confuses me. When I query one of the OIDs directly which have the corrupt value, it looks OK:
$ snmpget -v 1 -c public 3c39t1-01 1.3.6.1.2.1.17.4.3.1.1.0.13.86.32.1 +2.60 SNMPv2-SMI::mib-2.17.4.3.1.1.0.13.86.32.12.60 = Hex-STRING: 00 0D 56 2 +0 0C 3C
My first instinct is that I am doing something wrong. Can anyone see what it is?

Thank you for your time.


In reply to Net::SNMP result oddity by mackdav

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.