From 0f19d44c1d03f9db0a68b8a3c3220706dd682ce0 Mon Sep 17 00:00:00 2001 From: Jean Benoit Date: Fri, 4 Sep 2020 19:30:21 +0100 Subject: [PATCH] contrib: snmptest.pl SNMPwalk can't access to all variables/wrong sort MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Large quantity of data will be missing when snmptest.pl is used. The reason is a sort in lexicographic order: $ snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.250.255 |head iso.3.6.1.4.1.2021.250.255.2.1 = STRING:  "10.4.52.1" iso.3.6.1.4.1.2021.250.255.2.10 = STRING: "192.168.35.64" iso.3.6.1.4.1.2021.250.255.2.100 = STRING: "192.168.196.1" iso.3.6.1.4.1.2021.250.255.2.101 = STRING: "192.168.198.1" iso.3.6.1.4.1.2021.250.255.2.102 = STRING: "192.168.209.225" iso.3.6.1.4.1.2021.250.255.2.103 = STRING: "192.168.209.241" SNMPGetNext after "root.2.1" should give "root.2.2". Thus, lots of variables are missing. The function is now dependant on a CPAN module NetSNMP::OID, (debian/ubuntu package is called libsnmp-perl). This is probably not the most efficient way to do it: walking the whole tree will be much slower. Signed-off-by: Jean Benoit --- THANKS | 1 + contrib/snmptest.pl | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/THANKS b/THANKS index f5fd050..4bb123d 100644 --- a/THANKS +++ b/THANKS @@ -48,3 +48,4 @@ Sebastián Cramatte Mark Sangster Brent Swingle Mathieu Morier +Jean Benoit diff --git a/contrib/snmptest.pl b/contrib/snmptest.pl index c77b882..54093c7 100644 --- a/contrib/snmptest.pl +++ b/contrib/snmptest.pl @@ -23,9 +23,10 @@ # you set $dbg to 1 then output will be generated in /tmp. use strict; +use NetSNMP::OID; # Version info: -my $SNMPver = "snmp1.0"; +my $SNMPver = "snmp1.1"; my $DHCPver = "dhcp1.0"; my $VERSION = "$SNMPver/$DHCPver"; # @@ -193,7 +194,7 @@ sub ParseDataFile () { } close IN; if ($dbg) { - foreach (sort @validoidlist) { print DBG "ValidOID: $_\n"; } + foreach (sort Oidcmp @validoidlist) { print DBG "ValidOID: $_\n"; } } if ($dbg) { @@ -370,7 +371,7 @@ sub GetData ($) { @userquery = split (/\./, $userqueryoid); my $found = 0; - foreach (sort @validoidlist) { + foreach (sort Oidcmp @validoidlist) { $next = $_; print DBG "Comparing $userqueryoid vs. $_\n" if $dbg; @validoid = split (/\./, $_); @@ -432,6 +433,12 @@ sub Pong { $line = 0; } +sub Oidcmp { + my $oida = new NetSNMP::OID($a); + my $oidb = new NetSNMP::OID($b); + snmp_oid_compare($oida, $oidb); +} + ################################## START ################################## # # Main