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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.