I used snmpv1, blocking, and printf instead of print; also, I added DEBUG_ALL to make it more interesting:
# /usr/bin/perl
use strict;
use warnings;
use Net::SNMP qw(:snmp DEBUG_ALL);
my $OID = '1.3.6.1.2.1.1.3.0';
my ( $session, $error ) = Net::SNMP->session(
-hostname => shift || 'localhost',
-community => shift || 'public',
-version => 'snmpv1',
-debug => DEBUG_ALL,
);
my $result = $session->get_request( -varbindlist => [$OID], );
if ( !defined $result ) {
$error = $session->error();
printf "GET_REQUEST ERROR: %s: %s\n", $session->error();
$session->close();
exit(1);
}
printf "The TimeTicks for host '%s' is %s\n",
$session->hostname(), $result->{$OID}, "\n";
$session->close;
exit(0);