예제 #1
0
 function retrive($name, $keyname = false)
 {
     $this->_fields[] = $name;
     $this->_map[] = $name;
     $a = snmpwalkoid($this->_host, $this->_community, $name, 120000, 3);
     for (reset($a); $i = key($a); next($a)) {
         $j = strpos($i, '::') + 2;
         $v = substr($i, $j);
         $j = strpos($v, '.');
         $index = substr($v, $j + 1);
         $fmap = substr($v, 0, $j);
         $fname = str_replace(array('-', '.'), '', $fmap);
         $j = strpos($a[$i], ':');
         $value = substr($a[$i], $j + 2);
         if (($j = array_search($index, $this->index)) === false) {
             $this->index[] = $index;
             $j = count($this->index) - 1;
         }
         if (!isset($this->{$fname})) {
             $this->{$fname} = array();
             $this->_fields[] = $fname;
             $this->_map[] = $fmap;
         }
         $field =& $this->{$fname};
         $field[$j] = $value;
     }
     $this->count = count($this->index);
 }
예제 #2
0
function GetRoutingTable($host, $community, $rtrtype)
{
    global $w, $p;
    $OID = array("generic" => ".1.3.6.1.2.1.4.21.1.11", "riverstone" => ".1.3.6.1.2.1.4.24.4", "juniper" => ".1.3.6.1.2.1.4.24.4.1");
    if (!extension_loaded("snmp")) {
        myError($w, $p, "no snmp!!! - compile php with --with-snmp --enable-ucd-snmp-hack");
        exit;
    }
    if (strpos(strtoupper(PHP_OS), 'WIN') !== false) {
        // Windows snmp different
    } else {
        // Unix snmp different - need to set quickprint to be compatible
        // with Windows format. Windows does not have long print format
        // must test for os version as undefined function generates error
        // even with @
        snmp_set_quick_print(1);
    }
    // protect against bad users!
    if (!array_key_exists($rtrtype, $OID)) {
        $rtrtype = "generic";
    }
    $routes = @snmpwalkoid($host, $community, $OID[$rtrtype]);
    if (!$routes) {
        return 0;
    }
    for (reset($routes); $network = key($routes); next($routes)) {
        //here is the way to do it with RFC 2096 using ipCidrRouteMask
        //this is what we get back from the riverstone
        //meaning:  subnet IP, subnet mask, destination = ip destination ip
        if ($rtrtype == "riverstone") {
            //kill the destination
            list($oc1, $oc2, $oc3, $oc4, $oc5, $rest) = explode(".", strrev($network), 6);
            //take the subnetmask
            list($oc1, $oc2, $oc3, $oc4, $rest) = explode(".", $rest, 5);
            $mask = strrev(sprintf("%s.%s.%s.%s", $oc1, $oc2, $oc3, $oc4));
            //take the subnet addr
            list($oc1, $oc2, $oc3, $oc4, $rest) = explode(".", $rest, 5);
            $netaddr = strrev(sprintf("%s.%s.%s.%s", $oc1, $oc2, $oc3, $oc4));
        } else {
            // The Old way to do it with RFC 1213 MIBv2 (which is deprecated)
            // do some magic to obtain a unique, sortable array index to force the results
            // into ip address order. index will be x0000000000 where the digits are the
            // integer representation of the ip address padded with zeros.
            $mask = $routes[$network];
            // strip out last 4 octets from mib value - lots of .'s
            // complicate matters
            list($oc1, $oc2, $oc3, $oc4, $rest) = explode(".", strrev($network), 5);
            $netaddr = strrev(sprintf("%s.%s.%s.%s", $oc1, $oc2, $oc3, $oc4));
        }
        // $ind='x'.str_pad(inet_aton(substr($netaddr, strpos($netaddr, '.')+1)), 10, "0", STR_PAD_LEFT);
        $ind = 'x' . str_pad(inet_aton($netaddr), 10, "0", STR_PAD_LEFT);
        $result["{$ind}"] = array("rtrbase" => $netaddr, "rtrmask" => $mask);
    }
    //"rtrmask"=>substr($mask, strpos($mask, ' ')+1));
    return $result;
}
예제 #3
0
 public function viewStorageTable()
 {
     $storageIndexes = snmpwalkoid($this->hostname, $this->community, $this->hrStorage . $this->Index);
     array_walk($storageIndexes, 'Check_SNMP_Disk::convertValue');
     foreach ($storageIndexes as $storageIndex) {
         $this->doSNMPGet($storageIndex);
         if ($this->s == 0) {
             continue;
         }
         printf("%d: %s - Total: %g %s - Used: %g %s (%d%%) - Free: %g %s (%d%%)\n", $storageIndex, $this->d, $this->s, $this->uom, $this->u, $this->uom, $this->pu, $this->f, $this->uom, $this->pf);
     }
     exit(0);
 }
function ap_clients_aruba_wlan_controller($ip_wlan_controller, $community = "public")
{
    $APNumCli = array();
    #wlanAPRadioNumAssociatedClients
    $OID = ".1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.7";
    $walk = snmpwalkoid($ip_wlan_controller, $community, $OID);
    for (reset($walk); $i = key($walk); next($walk)) {
        $macDecimal = substr($i, 48, -2);
        $numCli = substr($walk[$i], 8);
        $macAddress = mac_address_dec2hex($macDecimal);
        if (array_key_exists($macAddress, $APNumCli)) {
            $APNumCli[$macAddress] += $numCli;
        } else {
            $APNumCli[$macAddress] = $numCli;
        }
        #echo "$macAddress --> $numCli"
    }
    return $APNumCli;
}
예제 #5
0
 function _getpeersfromrouter($config)
 {
     if ($config['snmp_community'] == '') {
         die('no community value set');
     }
     if (!$config['hostname']) {
         die('no hostname value set');
     }
     snmp_set_oid_numeric_print(1);
     snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
     if ($raw_snmp = snmpwalkoid($config['hostname'] . ':' . $config['port'], $config['snmp_community'], $this->base_oid)) {
         if ($rawfile = fopen($this->cachefile, 'w')) {
             fputs($rawfile, serialize($raw_snmp));
         } else {
             die('could not write to cache file! ' . $this->cachefile);
         }
     } else {
         die('connection to router failed!');
     }
 }
예제 #6
0
<?php

// --- Начало модуля: 'Таблица коммутации' ---
// Таблица коммутации для всех vlan
$dot1dTpFdbAddress = @snmpwalkoid($ip, $rcomm, ".1.3.6.1.2.1.17.7.1.2.2.1.2", $timeout, $retries);
// Статус записей
$dot1dTpFdbStatus = @snmpwalkoid($ip, $rcomm, ".1.3.6.1.2.1.17.7.1.2.2.1.3", $timeout, $retries);
// Список названий vlan
$dot1qTpVlanStaticName = @snmpwalkoid($ip, $rcomm, ".1.3.6.1.2.1.17.7.1.4.3.1.1", $timeout, $retries);
asort($dot1dTpFdbAddress);
// Оставляем в ключе массива только нужную информацию
$dot1dTpFdbAddress = keyscutvlanmac($dot1dTpFdbAddress);
// Оставляем в ключе массива только нужную информацию
$dot1dTpFdbStatus = keyscutvlanmac($dot1dTpFdbStatus);
// Оставляем в ключе массива только нужную информацию
$dot1qTpVlanStaticName = keyscut($dot1qTpVlanStaticName);
// Создаем шапку FDB таблицы
$swtable = "\n<table border=1 width='100%'>";
$swtable .= "\n\t<tr class='head'>\n\t\t<td class='tablehead' colspan=5>Таблица коммутации</td>\n\t</tr>";
$swtable .= "\n\t<tr class='head'>\n\t\t<td class='tablehead'>VID</td>\n\t\t";
$swtable .= "<td class='tablehead'>Название vlan</td>\n\t\t<td class='tablehead'>MAC-адрес</td>\n\t\t";
$swtable .= "<td class='tablehead'>Порт</td>\n\t\t<td class='tablehead'>Тип</td>";
//Выводим таблицу FDB
reset($dot1dTpFdbAddress);
for ($q = 0; $q < count($dot1dTpFdbAddress); $q++) {
    $stat_key = key($dot1dTpFdbAddress);
    $entry_stat = "unknown";
    if ($dot1dTpFdbStatus[$stat_key] == 1) {
        $entry_stat = "Other/Unknown (Возможно, заблокирован IMP)";
    }
    if ($dot1dTpFdbStatus[$stat_key] == 2) {
예제 #7
0
 /**
  * Executes native SNMP walk interface
  * 
  * @param string $ip
  * @param string $community
  * @param string $oid
  * @param bool   $cache
  * @param bool   $nowait
  * @return string
  */
 protected function snmpWalkNative($ip, $community, $oid, $cache = true)
 {
     $cachetime = time() - $this->cacheTime;
     $cachepath = self::CACHE_PATH;
     $cacheFile = $cachepath . $ip . '_' . $oid;
     $result = '';
     //cache handling
     if (file_exists($cacheFile)) {
         //cache not expired
         if (filemtime($cacheFile) > $cachetime and $cache == true) {
             $result = file_get_contents($cacheFile);
         } else {
             //cache expired - refresh data
             snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
             @($raw = snmpwalkoid($ip, $community, $oid, $this->timeoutNative, $this->retriesNative));
             if (!empty($raw)) {
                 foreach ($raw as $oid => $value) {
                     $result .= $oid . ' = ' . $value . "\n";
                 }
             } else {
                 @($value = snmpget($ip, $community, $oid, $this->timeoutNative, $this->retriesNative));
                 $result = $oid . ' = ' . $value;
             }
             file_put_contents($cacheFile, $result);
         }
     } else {
         //no cached file exists
         snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
         @($raw = snmprealwalk($ip, $community, $oid, $this->timeoutNative, $this->retriesNative));
         if (!empty($raw)) {
             foreach ($raw as $oid => $value) {
                 $result .= $oid . ' = ' . $value . "\n";
             }
         } else {
             @($value = snmpget($ip, $community, $oid, $this->timeoutNative, $this->retriesNative));
             $result = $oid . ' = ' . $value;
         }
         file_put_contents($cacheFile, $result);
     }
     return $result;
 }
예제 #8
0
파일: snmp.php 프로젝트: songchin/Cacti
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $port = 161, $timeout = 500, $environ = SNMP_POLLER) {
	global $config;

	$snmp_array = array();
	$temp_array = array();

	$retries = read_config_option("snmp_retries");
	if ($retries == "") $retries = 3;

	/* always use SNMP version 1 for UI stuff */
	if ($environ == SNMP_WEBUI) {
		$version = "1";
	}

	if (($config["php_snmp_support"] == true) && ($version == "1")) {
		$temp_array = @snmpwalkoid("$hostname:$port", $community, $oid, ($timeout * 1000), $retries);

		$o = 0;
		for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
			$snmp_array[$o]["oid"] = ereg_replace("^\.", "", $i);
			$snmp_array[$o]["value"] = format_snmp_string($temp_array[$i]);
			$o++;
		}
	}else{
		/* ucd/net snmp want the timeout in seconds */
		$timeout = ceil($timeout / 1000);

		if ($version == "1") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
		}elseif ($version == "2") {
			$snmp_auth = (read_config_option("snmp_version") == "ucd-snmp") ? SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER : "-c " . SNMP_ESCAPE_CHARACTER . $community . SNMP_ESCAPE_CHARACTER; /* v1/v2 - community string */
			$version = "2c"; /* ucd/net snmp prefers this over '2' */
		}elseif ($version == "3") {
			$snmp_auth = "-u $username -X $password"; /* v3 - username/password */
		}

		if (read_config_option("snmp_version") == "ucd-snmp") {
			$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " -v$version -t $timeout -r $retries $hostname:$port $snmp_auth $oid");
		}elseif (read_config_option("snmp_version") == "net-snmp") {
			$temp_array = exec_into_array(read_config_option("path_snmpwalk") . " $snmp_auth -v $version -t $timeout -r $retries $hostname:$port $oid");
		}

		if (sizeof($temp_array) == 0) {
			return 0;
		}

		for ($i=0; $i < count($temp_array); $i++) {
			$snmp_array[$i]["oid"] = trim(ereg_replace("(.*) =.*", "\\1", $temp_array[$i]));
			$snmp_array[$i]["value"] = format_snmp_string($temp_array[$i]);
		}
	}

	return $snmp_array;
}
예제 #9
0
<?php

//<--Начало модуля:'Информация о vlan'--
// Список названий vlan
$dot1qTpVlanStaticName = @snmpwalkoid($ip, $rcomm, ".1.3.6.1.2.1.17.7.1.4.3.1.1");
// Список отмеченных портов в вланах
$dot1qVlanStaticEgressPorts = @snmpwalkoid($ip, $rcomm, ".1.3.6.1.2.1.17.7.1.4.3.1.2");
// Список запрещенных портов в вланах
$dot1qVlanForbiddenEgressPorts = @snmpwalkoid($ip, $rcomm, ".1.3.6.1.2.1.17.7.1.4.3.1.3");
// Список нетегированных портов в вланах
$dot1qVlanStaticUntaggedPorts = @snmpwalkoid($ip, $rcomm, ".1.3.6.1.2.1.17.7.1.4.3.1.4");
// Оставляем в ключе массива только нужную информацию
$dot1qTpVlanStaticName = keyscut($dot1qTpVlanStaticName);
$dot1qVlanStaticEgressPorts = keyscut($dot1qVlanStaticEgressPorts);
$dot1qVlanForbiddenEgressPorts = keyscut($dot1qVlanForbiddenEgressPorts);
$dot1qVlanStaticUntaggedPorts = keyscut($dot1qVlanStaticUntaggedPorts);
$colspanvalue = $uniqueportscount[$ModelType] + 1;
// Создаем шапку таблицы с информацией о vlan
$swtable = "\n<table border=1 width='100%'>";
$swtable .= "\n\t<tr class='head'>\n\t\t<td class='tablehead' colspan={$colspanvalue}>Таблица vlan</td>\n\t</tr>";
$swtable .= "\n\t<tr class='head'>\n\t\t<td class='tablehead'>Vlan Name</td>";
for ($t = 1; $t < $colspanvalue; $t++) {
    if (strlen($t) == 1) {
        $vport = "0" . $t;
    } else {
        $vport = $t;
    }
    $swtable .= "\n\t\t<td class='tablehead'>" . $vport . "</td>";
}
$swtable .= "\n\t</tr>";
//Выводим таблицу с информацией о вланах
예제 #10
0
        @author david.mello@gmail.com   
        @date 2015-11-16 16:00
*/
$snmp_community = 'public';
$count = 0;
// VMWare Servers
$servers = array('SERVER1' => 'Short Description (to be improved)', 'SERVER2' => 'Model: R710 | Service Tag: XXXXXXX', 'SERVERN' => 'Model: R730 | Service Tag: YYYYYYY');
while ($server = key($servers)) {
    // faz um snmpwalk para pegar os OIDs para saber quantos hosts temos na VM
    $a = snmpwalkoid($server, $snmp_community, ".1.3.6.1.4.1.6876.2.1.1.2");
    $phisical_memory_tmp = snmp2_get($server, $snmp_community, 'SNMPv2-SMI::enterprises.6876.3.2.1.0');
    $phisical_memory = str_replace("\"", "", substr($phisical_memory_tmp, strrpos($phisical_memory_tmp, ':') + 1));
    $phisical_memory_gb = round($phisical_memory / 1024 / 1024);
    $procs = snmp2_get($server, $snmp_community, 'HOST-RESOURCES-MIB::hrDeviceDescr');
    //$procts = preg_match( '/cpu/i', snmp2_get( $server, $snmp_community, 'HOST-RESOURCES-MIB::hrDeviceDescr' ) );
    $b = snmpwalkoid($server, $snmp_community, 'HOST-RESOURCES-MIB::hrDeviceDescr');
    $count_procs = 0;
    foreach ($b as $cpus) {
        if (preg_match('/cpu/i', $cpus)) {
            $count_procs++;
        }
    }
    echo "<table border=\"1\" colspacing=\"0\" cellspacing=\"0\" width=\"1024\">\n";
    echo "<tr><td colspan=\"5\"><p> {$server} | Cores: {$count_procs} | Memory: {$phisical_memory} ({$phisical_memory_gb} GB) | {$servers[$server]}</p></td></tr>";
    echo "<tr>\n";
    echo "  <td><b>Nome Host</b></td><td style=\"width:500px\"><b>Kernel Version</b></td><td style=\"width:60px\"  align=\"center\"><b>CPUs</b></td><td style=\"width:70px\" align=\"center\"><b>RAM</b></td><td style=\"width:120px\"  align=\"center\"><b>Power Status</b></td>\n";
    echo "</tr>\n";
    $total_procs = 0;
    $total_mem = 0;
    $total_vms = 0;
    for (reset($a); $i = key($a); next($a)) {
예제 #11
0
    }
    // Статус линка
    $cableDiagLinkStatus[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.3." . $pi, $timeout, $retries);
    // Статус 1-й пары
    $cableDiagPair1Status[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.4." . $pi, $timeout, $retries);
    // Статус 2-й пары
    $cableDiagPair2Status[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.5." . $pi, $timeout, $retries);
    // Длина 1-й пары
    $cableDiagPair1Length[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.8." . $pi, $timeout, $retries);
    // Длина 2-й пары
    $cableDiagPair2Length[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.9." . $pi, $timeout, $retries);
}
// Список названий vlan
$dot1qTpVlanStaticName = @snmpwalkoid($ip, $rcomm, ".1.3.6.1.2.1.17.7.1.4.3.1.1", $timeout, $retries);
// Список нетегированных портов в вланах
$dot1qVlanStaticUntaggedPorts = @snmpwalkoid($ip, $rcomm, ".1.3.6.1.2.1.17.7.1.4.3.1.4", $timeout, $retries);
// Оставляем в ключе массива только нужную информацию
$dot1qTpVlanStaticName = keyscut($dot1qTpVlanStaticName);
// Оставляем в ключе массива только нужную информацию
$dot1qVlanStaticUntaggedPorts = keyscut($dot1qVlanStaticUntaggedPorts);
// Заполняем массив с vlan'ами пустотой, иначе array_splice глючит безбожно
$untag_vlan = array_fill(0, $uniqueportscount[$ModelType], '');
for ($t = 0; $t < count($dot1qTpVlanStaticName); $t++) {
    $vlan_name = $dot1qTpVlanStaticName[key($dot1qTpVlanStaticName)];
    $vlan_name = str_ireplace('"', "", $vlan_name);
    $vid = key($dot1qTpVlanStaticName);
    $uports = $dot1qVlanStaticUntaggedPorts[$vid];
    $uports = stripstr($uports);
    // Чит для 3526, когда вместо hex-строки возвращается string
    if (strlen($uports) == 4) {
        $uports = strtohex($uports);
 /**
  * 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 _snmpWalkOid($oid)
 {
     trigger_error('start', E_USER_NOTICE);
     trigger_error("oid={$oid}", E_USER_NOTICE);
     $retour = snmpwalkoid($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;
 }
예제 #13
0
     if ($userinf = @snmpget($iptemp, $community, ".1.3.6.1.2.1.1.4.0")) {
         if (strpos(strtoupper(PHP_OS), 'WIN') !== false) {
             $snmpoffset = 0;
             // no offset for Windows
         } else {
             $snmpoffset = 8;
         }
         $userinf = substr($userinf, $snmpoffset);
         // only query others if first query was a success
         $descrip = substr(@snmpget($iptemp, $community, ".1.3.6.1.2.1.1.1.0"), $snmpoffset);
         $hname = substr(@snmpget($iptemp, $community, ".1.3.6.1.2.1.1.5.0"), $snmpoffset);
         $location = substr(@snmpget($iptemp, $community, ".1.3.6.1.2.1.1.6.0"), $snmpoffset);
         // get the interface table while we are at it and check the subnet
         // mask - could be multiple interfaces on router
         // array contains ip address as key and mask as value
         $interfaces = snmpwalkoid($iptemp, $community, ".1.3.6.1.2.1.4.20.1.3");
         foreach ($interfaces as $key => $value) {
             if (strstr($key, $iptemp)) {
                 // found exact match of interface - compare mask
                 if (!strstr($value, inet_ntoa(inet_aton(ALLNETS) + 1 - $subnetsize))) {
                     insert($f, textbr());
                     myError($f, $p, my_("The subnet mask configured on the device appears to be incorrect!") . "\n", FALSE);
                 }
                 break;
             }
         }
     } else {
         // reset failed query to original value
         $userinf = $row["userinf"];
     }
 }
<?php

$mac_address = snmpwalkoid($argv[1], "public@30", ".1.3.6.1.2.1.17.4.3.1.1");
echo "{$argv['1']} public .1.3.6.1.2.1.17.4.3.1.1 - mac_address\n";
echo "{$argv['1']} public .1.3.6.1.2.1.17.4.3.1.2 - bridge_port\n";
for (reset($mac_address); $i = key($mac_address); next($mac_address)) {
    echo "{$i}: {$mac_address[$i]}\n";
}
echo "\n";
$bridge_port = snmpwalkoid($argv[1], "public@30", ".1.3.6.1.2.1.17.4.3.1.2");
echo "{$argv['1']} public .1.3.6.1.2.1.17.4.3.1.2 - bridge_port\n";
for (reset($bridge_port); $i = key($bridge_port); next($bridge_port)) {
    echo "{$i}: {$bridge_port[$i]}\n";
}
echo "\n";
$ifIndex = snmpwalkoid($argv[1], "public@30", ".1.3.6.1.2.1.17.1.4.1.2");
echo "{$argv['1']} public .1.3.6.1.2.1.17.1.4.1.2   - ifIndex\n";
for (reset($ifIndex); $i = key($ifIndex); next($ifIndex)) {
    echo "{$i}: {$ifIndex[$i]}\n";
}
echo "\n";
$ifName = snmpwalkoid($argv[1], "public@30", ".1.3.6.1.2.1.31.1.1.1.1");
echo "{$argv['1']} public .1.3.6.1.2.1.31.1.1.1.1    - ifName\n";
for (reset($ifName); $i = key($ifName); next($ifName)) {
    echo "{$i}: {$ifName[$i]}\n";
}
echo "\n";
예제 #15
0
파일: LMS.class.php 프로젝트: bochniak/lms
 function WIFI_GetAllSignal($ip, $community)
 {
     $tx_bytes_snmp = @snmpwalkoid($ip, $community, ".1.3.6.1.4.1.14988.1.1.1.2.1.3");
     $i = 0;
     $devices = array();
     if (is_array($tx_bytes_snmp)) {
         $oid_tx_rate = '.1.3.6.1.4.1.14988.1.1.1.2.1.8';
         $oid_rx_rate = '.1.3.6.1.4.1.14988.1.1.1.2.1.9';
         $oid_tx_packets = '.1.3.6.1.4.1.14988.1.1.1.2.1.6';
         $oid_rx_packets = '.1.3.6.1.4.1.14988.1.1.1.2.1.7';
         $oid_tx_bytes = '.1.3.6.1.4.1.14988.1.1.1.2.1.4';
         $oid_rx_bytes = '.1.3.6.1.4.1.14988.1.1.1.2.1.5';
         while (list($indexOID, $rssi) = each($tx_bytes_snmp)) {
             $oidarray = explode(".", $indexOID);
             $end_num = count($oidarray);
             $mac = "";
             for ($counter = 2; $counter < 8; $counter++) {
                 $temp = dechex($oidarray[$end_num - $counter]);
                 if ($oidarray[$end_num - $counter] < 16) {
                     $temp = "0" . $temp;
                 }
                 if ($counter == 7) {
                     $mac = $temp . $mac;
                 } else {
                     $mac = ":" . $temp . $mac;
                 }
             }
             if ($txr = @snmpwalk($ip, $community, $oid_tx_rate)) {
                 $txr = str_replace("Gauge32:", "", $txr[$i]);
                 $devices[$i]['tx_rate'] = $txr / 1000000;
             } else {
                 $devices[$i]['tx_rate'] = 0;
             }
             if ($rxr = @snmpwalk($ip, $community, $oid_rx_rate)) {
                 $rxr = str_replace("Gauge32:", "", $rxr[$i]);
                 $devices[$i]['rx_rate'] = $rxr / 1000000;
             } else {
                 $devices[$i]['rx_rate'] = 0;
             }
             if ($txp = @snmpwalk($ip, $community, $oid_tx_packets)) {
                 $txp = str_replace("Counter32:", "", $txp[$i]);
                 $devices[$i]['tx_packets'] = $txp;
             } else {
                 $devices[$i]['tx_packets'] = 0;
             }
             if ($rxp = @snmpwalk($ip, $community, $oid_rx_packets)) {
                 $rxp = str_replace("Counter32:", "", $rxp[$i]);
                 $devices[$i]['rx_packets'] = $rxp;
             } else {
                 $devices[$i]['rx_packets'] = 0;
             }
             if ($txb = @snmpwalk($ip, $community, $oid_tx_bytes)) {
                 $txb = str_replace("Counter32:", "", $txb[$i]);
                 $devices[$i]['tx_bytes'] = $txb;
             } else {
                 $devices[$i]['tx_bytes'] = 0;
             }
             if ($rxb = @snmpwalk($ip, $community, $oid_rx_bytes)) {
                 $rxb = str_replace("Counter32:", "", $rxb[$i]);
                 $devices[$i]['rx_bytes'] = $rxb;
             } else {
                 $devices[$i]['rx_bytes'] = 0;
             }
             $devices[$i]['rx_signal'] = str_replace("INTEGER:", "", $rssi);
             $devices[$i]['mac'] = strtoupper($mac);
             $i++;
         }
     }
     return $devices;
 }
예제 #16
0
 /**
  * Do snmpwalkoid
  *
  * @param unknown_type $rootOID
  * @return array Array of values
  */
 public function GetFullTree($rootOID = null)
 {
     try {
         $retval = @snmpwalkoid($this->Connection, $this->Community, $rootOID, $this->Timeout);
     } catch (Exception $e) {
         $this->RaiseWarning("Cannot walkoid through {$this->Connection}/{$this->Community}/{$rootOID}" . $e->__toString());
     }
     return $retval;
 }
<?php

$a = snmpwalkoid($argv[1], "public", "");
for (reset($a); $i = key($a); next($a)) {
    echo "{$i}: {$a[$i]}\n";
}
예제 #18
0
 function snmpwalkoid($oid)
 {
     return snmpwalkoid($this->hostname, $this->snmpsetup['community'], $oid);
 }
예제 #19
0
 /**
  * Do snmpwalkoid
  *
  * @param unknown_type $rootOID
  * @return array Array of values
  */
 public function getFullTree($rootOID = null)
 {
     $retval = @snmpwalkoid("{$this->host}:{$this->port}", $this->community, $rootOID, $this->timeout);
     return $retval;
 }