mackdav has asked for the wisdom of the Perl Monks concerning the following question:
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:
Running it results in output like this:#!/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;
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:[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]
My first instinct is that I am doing something wrong. Can anyone see what it is?$ 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
Thank you for your time.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Net::SNMP result oddity
by glide (Pilgrim) on Jul 27, 2007 at 15:47 UTC | |
by mackdav (Novice) on Jul 27, 2007 at 16:25 UTC | |
by mackdav (Novice) on Jul 27, 2007 at 16:59 UTC | |
Re: Net::SNMP result oddity
by McDarren (Abbot) on Jul 27, 2007 at 15:22 UTC | |
Re: Net::SNMP result oddity
by traveler (Parson) on Jul 27, 2007 at 15:41 UTC | |
Re: Net::SNMP result oddity
by gt2847c (Initiate) on Jul 29, 2007 at 03:32 UTC | |
Re: Net::SNMP result oddity
by andyford (Curate) on Jul 27, 2007 at 17:44 UTC |