Paste number 77950: Net::SNMP attempt

Index of paste annotations: 1 | 2

Paste number 77950: Net::SNMP attempt
Pasted by: bancus
When:2 years, 10 months ago
Share:Tweet this! | http://paste.lisp.org/+1O5A
Channel:#swhack
Paste contents:
Raw Source | XML | Display As
#!/usr/bin/perl
#!/usr/bin/perl

use Net::SNMP;

$ENV{'MIBS'}="RFC1213-MIB";
$SNMP_TARGET = "serenity";
$SNMP_COMMUNITY = "public";

$SESSION = new SNMP::Session (DestHost => $SNMP_TARGET, Community => $SNMP_COMMUNITY, Version => 1);

$VLIST = new SNMP::VarList(['ifInOctets.21'],['ifOutOctets.21']);

@INFO = $SESSION->getnext($VLIST);

print "Bytes In: ${VLIST[0]}";
print "Bytes Out: ${VLIST[1]}";

Annotations for this paste:

Annotation number 1: Working Net::SNMP example.
Pasted by: xover
When:2 years, 10 months ago
Share:Tweet this! | http://paste.lisp.org/+1O5A/1
Paste contents:
Raw Source | Display As
#!/usr/bin/perl

use strict;
use warnings;

use SNMP;

use constant OIDsysObjectID => '.1.3.6.1.2.1.1.2.0';

my $snmp = new SNMP::Session(
  DestHost       => 'host.example.com',
  Community      => 'snmp_community_string',
  Version        => '2c',
  UseSprintValue => 1,
);

my $sysOID = $id->get(OIDsysObjectID);

Annotation number 2: New Version
Pasted by: bancus
When:2 years, 10 months ago
Share:Tweet this! | http://paste.lisp.org/+1O5A/2
Paste contents:
Raw Source | Display As
#!/usr/bin/perl -w

use strict;
use Net::SNMP;

my $session = new Net::SNMP->session (-hostname => "serenity", -community => "public");

my $ifInOctets = "ifInOctets.21";
my $ifOutOctets = "ifOutOctets.21";

my $result = $session->get_request(-varbindlist => [$ifInOctets, $ifOutOctets]);

printf ("Bytes In: %s\n Bytes Out: %s", $result->{$ifInOctets}, $result->{$ifOutOctets});

$session->close;

exit 0;

Colorize as:
Show Line Numbers
Index of paste annotations: 1 | 2

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.