<?php

require_once dirname(__FILE__) . '/snmp_include.inc';
$hostname = "php.net";
$ip = gethostbyname($hostname);
if (ip2long($ip) === FALSE) {
    echo "Could not resolve {$hostname} properly!\n";
    exit(1);
}
$port = 1161;
$session = new SNMP(SNMP::VERSION_1, "{$hostname}:{$port}", $community, $timeout, $retries);
$info = $session->info;
if (strcmp($info["hostname"], "{$ip}:{$port}") !== 0) {
    echo "'" . $info["hostname"] . "' != '{$ip}:{$port}'\n";
}
var_dump($session->close());
Example #2
0
 /**
  * Executes PHP 5.4 SNMP set interface
  * 
  * @param string $ip
  * @param string $community
  * @param array  $data
  * @return string
  */
 protected function snmpSetClass($ip, $community, $data)
 {
     $result = '';
     if (!empty($data)) {
         if (is_array($data)) {
             foreach ($data as $io => $each) {
                 if (isset($each['oid']) and (isset($each['type']) and isset($each['value']))) {
                     $session = new SNMP(SNMP::VERSION_2c, $ip, $community, $this->timeoutNative, $this->retriesNative);
                     @($pushResult = $session->set($each['oid'], $each['type'], $each['value']));
                     $session->close();
                     if ($pushResult) {
                         $result .= trim($this->snmpWalkClass($ip, $community, $each['oid'], false)) . "\n";
                     }
                 } else {
                     throw new Exception(self::EX_WRONG_DATA);
                 }
             }
         } else {
             throw new Exception(self::EX_WRONG_DATA);
         }
     }
     return $result;
 }