I use the following simple script at the command line to run a few mibs on a cable modem. I need help converting this command line script to a webinterface script.
The script is run from the command line as follows:
>myscript.pl <community string> <hostname>
I can hard code the community string into the script, but I need an input form on the new webscript so the user can manually enter the <hostname> for the script to sun on.
#!C:\perl\bin\perl -w
use strict;
use BER;
use SNMP_Session;
### Prototypes
sub usage($ );
my $hostname = $ARGV[0] || usage (1);
#my $community = $ARGV[1] || usage (1);
my $session;
## Set this if you want to see the OID for all printed values.
my $print_oids_p = 0;
die unless ($session = SNMP_Session->open ($hostname, $community, 161));
my @base_oids =
(
encode_oid (split ('\.', '1.3.6.1.2.1.69.1.4.5')), # Bootfile Name
encode_oid (split ('\.', '1.3.6.1.2.1.10.127.1.1.4.
1.5')), # DS SNR
encode_oid (split ('\.', '1.3.6.1.2.1.10.127.1.1.1.
1.6')), # RX PWR
encode_oid (split ('\.', '1.3.6.1.2.1.10.127.1.2.2.
1.3')), # TX PWR
encode_oid (split ('\.', '1.3.6.1.2.1.10.127.1.1.1.
1.2')), # DS FREQ
encode_oid (split ('\.', '1.3.6.1.2.1.10.127.1.1.2.
1.2')), # US FREQ
encode_oid (split ('\.', '1.3.6.1.2')), # modem SysInfo
);
my $oid;
my $i;
my @next_oids = @base_oids;
ROW_LOOP:
for (;;) {
if ($session->getnext_request
_response (@next_oids)) {
my $response = $session->pdu_buffer;
my ($bindings, $binding, $oid, $value);
my ($base_oid);
($bindings) = $session->decode_get_respo
nse ($response);
@next_oids = ();
foreach $base_oid (@base_oids) {
($binding,$bindings) = decode_sequence ($bindings);
($oid,$value) = decode_by_template ($binding, "%O%@");
last ROW_LOOP
unless BER::encoded_oid_prefix_p ($base_oid, $oid);
push @next_oids, $oid;
print pretty_print ($value);
print ' [',pretty_print ($oid), "]" if $print_oids_p;
print "\n";
}
} else {
die "No response received.\n";
}
}
$session->close ();
1;
sub usage ($ )
{
print STDERR "Usage: $0 hostname community\n";
exit (1) if $_[0];
}