Skip to content

Instantly share code, notes, and snippets.

@0xack13
Last active October 9, 2015 07:28
Show Gist options
  • Select an option

  • Save 0xack13/3461931 to your computer and use it in GitHub Desktop.

Select an option

Save 0xack13/3461931 to your computer and use it in GitHub Desktop.
Perl SNMP Sample
#! /usr/local/bin/perl
### To install Perl SNMP Module: perl -MCPAN -e shell ; "install SNMP"
use strict;
use warnings;
use Net::SNMP;
my $OID_sysUpTime = '1.3.6.1.2.1.1.3.0';
my ($session, $error) = Net::SNMP->session(
-hostname => shift || 'localhost',
-community => shift || 'public',
);
if (!defined $session) {
printf "ERROR: %s.\n", $error;
exit 1;
}
my $result = $session->get_request(-varbindlist => [ $OID_sysUpTime ],);
if (!defined $result) {
printf "ERROR: %s.\n", $session->error();
$session->close();
exit 1;
}
printf "The sysUpTime for host '%s' is %s.\n",
$session->hostname(), $result->{$OID_sysUpTime};
$session->close();
exit 0;
#!/usr/bin/perl
use NetSNMP::agent;
my $agent;
sub myhandler {
my ($handler, $registration_info, $request_info, $requests) = @_;
my $request;
$request->setValue(ASN_OCTET_STRING, "hello\n");
}
$agent = new NetSNMP::agent(
'Name' => 'my_agent_name',
);
$agent->register(
"my_agent_name",
".1.3.6.1.4.1.8072.9999.9999.9999",
\&myhandler
);
$agent->main_loop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment