#!/usr/bin/perl
## CGI /Perl Prog to get the OID and
## using get _req getting the reqested data
use strict;
use Net::SNMP;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser warningsToBrowser); ## Used to see if any errors in fix it out
my ($IP,$Cmty,$Oid);
my $ob = new CGI;
print $ob->header;
print $ob->start_html(-title=>"SNMP Get_Request" );
print "
";
print $ob->h2("SNMP Get Requested Information");
print $ob->hr;
if ( $ob->param() )
{
$IP = $ob->param('ip');
chomp($IP);
$Cmty = $ob->param('community');
chomp($Cmty);
$Oid = $ob->param('oid');
chomp($Oid);
print $ob->b("INFO");
print $ob->em(" IP : $IP Community: $Cmty Oid : $Oid
");
my $sesobj = &createSession($ob,$IP,$Cmty);
print $ob->em("Session Obj : $sesobj");
}
else
{
print $ob->start_form(-name=>"get_req",-method=>"POST",
-action=>"http://localhost/cgi-bin/cgiprog/snmp/get_req.cgi");
print $ob->em("IP Address ");
print $ob->textfield(-name=>"ip");
print $ob->br($ob->br);
print $ob->em("Community ");
print $ob->textfield(-name=>"community");
print $ob->br($ob->br);
print $ob->em("Object ID ");
print "   ";
print $ob->textfield(-name=>"oid");
print $ob->br($ob->br);
print "         ";
print $ob->submit(-name=>"Submit", -value=>"Submit" );
print "         ";
print $ob->reset;
}
print $ob->end_form;
print $ob->end_html;
sub createSession()
{
my ($object, $ip, $cmty) = @_;
## print $object->em("IP : $ip
Cmty : $cmty
" ); ## Checking whether val r obtained here or not
chomp($ip);
chomp($cmty);
my ($session, $error) = Net::SNMP->session(-hostname => $ip,
-community=> $cmty,
-port => '161'
);
if (!defined ($session))
{
print ("Err Creation Session Obj: $session->error ");
exit 1;
}
else
{
print "Session created ";
}
}