#!/usr/bin/perl -w # Copyright (c) 2001 TANAKA Kei $snmpget = '/usr/local/ucd-snmp/bin/snmpget'; $agent = 'host'; $community = 'public'; @IncomingBytes = ( '.1.3.6.1.4.1.410.1.1.7.1.0', 1, 4 ); @OutgoingBytes = ( '.1.3.6.1.4.1.410.1.1.7.2.0', 1, 4 ); print exec_snmpget(@IncomingBytes), "\n"; print exec_snmpget(@OutgoingBytes), "\n"; print "uptime\n"; print $agent, "\n"; exit 0; sub exec_snmpget { my ($oid, $start, $bytes) = @_; my ($count, $value) = ( 0, 0 ); open(SNMP, "$snmpget $agent $community $oid|"); while () { chomp; foreach (split) { if (/^[0-9a-fA-F][0-9a-fA-F]$/) { $count++; if ($count >= $start && $bytes > 0) { $bytes--; $value += oct('0x'.$_) << (($count-$start)<<3); } } } } close(SNMP); return $value; }