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".
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.