Notdeadyet has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write a Perl script that uses Net::SNMP to query RFC 2674 enabled Ethernet switches. One of the "Textual Conventions" defined in the MIB is a "PortList" that the MIB defines as:
PortList ::= TEXTUAL-CONVENTION STATUS current DESCRIPTION "Each octet within this value specifies a set of eight ports, with the first octet specifying ports 1 through 8, the second octet specifying ports 9 through 16, etc. Within each octet, the most significant bit represents the lowest numbered port, and the least significant bit represents the highest numbered port. Thus, each port of the bridge is represented by a single bit within the value of this object. If that bit has a value of '1' then that port is included in the set of ports; the port is not included if its bit has a value of '0'." SYNTAX OCTET STRING
What I would like to do is convert the hex string to an Perl array where the variable is either a one or a zero depending on the hex string. What I've written so far is:
#!/usr/bin/perl -w use strict; use diagnostics; use Data::Dumper; use Net::SNMP; use Carp; my $debug = 0; my $ports = "1.3.6.1.2.1.17.7.1.4.2.1.5.0.1"; my ($session, $error) = Net::SNMP->session( version=> 2, -hostname => "switch", -community=> "public"); if (!$session) { croak("Net::SNMP Session not created\n"); } my $result = $session->get_request(-varbindlist => $ports]); + if (!$result) { my $err = $session->error(); print "ERROR: $err \n"; croak("no results from get_bulk_result"); } $session->close(); my $portstr = $result->{$ports}; print "The port string is: $portstr\n";
Which produces the following output: 0xfffbff0000000000000000
I know I need to use unpack to make the conversion, but I'm not sure how to go about it.
Thanks in advance for your generous help.
Notdeadyet
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Convert SNMP Octet String to Array
by Illuminatus (Curate) on Sep 30, 2008 at 21:28 UTC | |
|
Re: Convert SNMP Octet String to Array
by GrandFather (Saint) on Sep 30, 2008 at 22:00 UTC | |
|
Re: Convert SNMP Octet String to Array
by moritz (Cardinal) on Sep 30, 2008 at 21:27 UTC |