コード例 #1
0
 function walk($oid, $suffix_as_key = FALSE)
 {
     switch ($this->version) {
         case self::VERSION_1:
             if ($suffix_as_key) {
                 $this->result = snmpwalk($this->host, $this->community, $oid);
             } else {
                 $this->result = snmprealwalk($this->host, $this->community, $oid);
             }
             break;
         case self::VERSION_2C:
         case self::VERSION_2c:
             if ($suffix_as_key) {
                 $this->result = snmp2_walk($this->host, $this->community, $oid);
             } else {
                 $this->result = snmp2_real_walk($this->host, $this->community, $oid);
             }
             break;
         case self::VERSION_3:
             if ($suffix_as_key) {
                 $this->result = snmp3_walk($this->host, $this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase, $oid);
             } else {
                 $this->result = snmp3_real_walk($this->host, $this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase, $oid);
             }
             break;
     }
     return $this->result;
 }
コード例 #2
0
ファイル: snmp_helper.php プロジェクト: Opmantek/open-audit
 function my_snmp_walk($ip, $credentials, $oid)
 {
     $timeout = '30000000';
     $retries = '0';
     switch ($credentials->credentials->version) {
         case '1':
             $array = @snmpwalk($ip, $credentials->credentials->community, $oid, $timeout, $retries);
             break;
         case '2':
             $array = @snmp2_walk($ip, $credentials->credentials->community, $oid, $timeout, $retries);
             break;
         case '3':
             $sec_name = $credentials->credentials->security_name ?: '';
             $sec_level = $credentials->credentials->security_level ?: '';
             $auth_protocol = $credentials->credentials->authentication_protocol ?: '';
             $auth_passphrase = $credentials->credentials->authentication_passphrase ?: '';
             $priv_protocol = $credentials->credentials->privacy_protocol ?: '';
             $priv_passphrase = $credentials->credentials->privacy_passphrase ?: '';
             $array = @snmp3_walk($ip, $sec_name, $sec_level, $auth_protocol, $auth_passphrase, $priv_protocol, $priv_passphrase, $oid, $timeout, $retries);
             break;
         default:
             return false;
             break;
     }
     if (!is_array($array)) {
         return false;
     }
     foreach ($array as $i => $value) {
         $array[$i] = trim($array[$i]);
         if ($array[$i] == '""') {
             $array[$i] = '';
         }
         if (strpos($array[$i], '.') === 0) {
             $array[$i] = substr($array[$i], 1);
         }
         // remove the first and last characters if they are "
         if (substr($array[$i], 0, 1) == "\"") {
             $array[$i] = substr($array[$i], 1, strlen($array[$i]));
         }
         if (substr($array[$i], -1, 1) == "\"") {
             $array[$i] = substr($array[$i], 0, strlen($array[$i]) - 1);
         }
         // remove some return strings
         if (strpos(strtolower($array[$i]), '/etc/snmp') !== false or strpos(strtolower($array[$i]), 'no such instance') !== false or strpos(strtolower($array[$i]), 'no such object') !== false or strpos(strtolower($array[$i]), 'not set') !== false or strpos(strtolower($array[$i]), 'unknown value type') !== false) {
             $array[$i] = '';
         }
         // remove any quotation marks
         $array[$i] = str_replace('"', ' ', $array[$i]);
         // replace any line breaks with spaces
         $array[$i] = str_replace(array("\r", "\n"), " ", $array[$i]);
     }
     return $array;
 }
コード例 #3
0
echo "GET multiple\n";
var_dump(snmp3_get($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0'), $timeout, $retries));
echo "GETNEXT single\n";
var_dump(snmp3_getnext($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
echo "WALK single on single OID\n";
$z = snmp3_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries);
var_dump(gettype($z));
var_dump(count($z));
var_dump($z);
echo "REALWALK single on single OID\n";
$z = snmp3_real_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries);
var_dump(gettype($z));
var_dump(count($z));
var_dump($z);
echo "WALK multiple on single OID\n";
$z = snmp3_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1', $timeout, $retries);
var_dump(gettype($z));
var_dump(count($z));
var_dump(key($z));
var_dump(array_shift($z));
echo "REALWALK multiple on single OID\n";
$z = snmp3_real_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, 'AES', '', '.1.3.6.1.2.1.1', $timeout, $retries);
var_dump(gettype($z));
var_dump(count($z));
var_dump(key($z));
var_dump(array_shift($z));
echo "SET single OID\n";
$oid1 = 'SNMPv2-MIB::sysContact.0';
$oldvalue1 = snmp3_get($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, $timeout, $retries);
$newvalue1 = $oldvalue1 . '0';
$z = snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, 's', $newvalue1, $timeout, $retries);
コード例 #4
0
 /**
  * Méthode d'interrogation snmp.
  * Comparée au snmpget elle gère les type compteurs
  *  
  * @param   $oid  string oid de la donnée
  * @param    $time_derived boolean optionnel : false par défaut, le compteur doit il être divisé par le temp 
  * @return string 
  */
 protected final function _snmpWalk($oid)
 {
     trigger_error('start', E_USER_NOTICE);
     trigger_error("oid={$oid}", E_USER_NOTICE);
     switch ($this->getInput('version')) {
         case 'auto':
             $retour = snmpwalk($this->getInput('host') . ":" . $this->getInput('port'), $this->getInput('community'), $oid, $this->getInput('timeout') * 1000000, $this->getInput('retries'));
             break;
         case '2':
             $retour = snmp2_walk($this->getInput('host') . ":" . $this->getInput('port'), $this->getInput('community'), $oid, $this->getInput('timeout') * 1000000, $this->getInput('retries'));
             break;
         case '3':
             $retour = snmp3_walk($this->getInput('host') . ":" . $this->getInput('port'), $this->getInput('community'), $oid, $this->getInput('timeout') * 1000000, $this->getInput('retries'));
             break;
     }
     $retour = snmpwalk($this->getInput('host') . ":" . $this->getInput('port'), $this->getInput('community'), $oid, $this->getInput('timeout') * 1000000, $this->getInput('retries'));
     foreach ($retour as $i => $valeur) {
         $retour[$i] = $this->_makeValueClean($valeur);
     }
     return $retour;
 }