本文整理汇总了PHP中snmpwalk函数的典型用法代码示例。如果您正苦于以下问题:PHP snmpwalk函数的具体用法?PHP snmpwalk怎么用?PHP snmpwalk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmpwalk函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetTree
/**
* Do snmpwalk
*
* @param unknown_type $rootOID
* @return array Array of values
*/
public function GetTree($rootOID = null)
{
try {
$retval = @snmpwalk($this->Connection, $this->Community, $rootOID, $this->Timeout);
} catch (Exception $e) {
$this->RaiseWarning("Cannot walk through {$this->Connection}/{$this->Community}/{$rootOID}" . $e->__toString());
}
return $retval;
}
示例2: snmpwalk
<tr>
<td colspan = "1">
<a href='index.php'>HOME</td>
<td style="height:600px;width:2000px;vertical-align:top;">
<center><br>
<form action = "a3n3.php" method = "POST">
<?php
$IP = $_POST["IP"];
$PORT = $_POST["PORT"];
$COMMUNITY = $_POST["COMMUNITY"];
$int = snmpwalk("{$IP}:{$PORT}", "{$COMMUNITY}", '1.3.6.1.2.1.2.2.1.1', 100000, 5);
$device = "{$COMMUNITY}-{$IP}-{$PORT}";
if ($int) {
echo "The interfaces of the selected device {$COMMUNITY}, {$IP} and {$PORT} are:";
echo "<br><table border = '1'>";
foreach ($int as $x) {
$i = explode(' ', $x);
echo "<tr><td><input type = 'checkbox' name ='list[]' value = {$i['1']},{$device}> {$i['1']}</td></tr>";
}
} else {
echo "<br>The device is down. Cannot add<br>";
}
?>
</table><br>
示例3: session_start
<?php
/**
Consulta o nº de processos para o I.P da sessão e retorna no formato para ser lido pelo gráfico.
*/
session_start();
$ip = $_SESSION["ip"];
$num_processes = snmpwalk($ip, "public", "1.3.6.1.2.1.25.1.6");
echo "&label=" . date('H:i:s') . "&value=" . str_replace("Gauge32: ", '', $num_processes[0]);
示例4: SNMPwalk_Render
function SNMPwalk_Render(&$parser, $snmphost = '127.0.0.1', $com = 'public', $snmpoid = 'SNMPv2-SMI::mib-2.1.6.0', $prefix, $suffix)
{
$arr = snmpwalk($snmphost, $com, $snmpoid, 50000);
$result = '';
foreach ($arr as $value) {
if (isset($prefix)) {
$result .= "{$prefix} ";
}
$result .= clean_Result($value) . " ";
if (isset($suffix)) {
$result .= $suffix;
}
}
return $result;
}
示例5: snmp_walk
function snmp_walk($snmp_host, $snmp_community, $snmp_oid, $snmp_version)
{
if (extension_loaded("snmp")) {
if ($snmp_version == "1") {
if ($snmp_return = @snmpwalk($snmp_host, $snmp_community, $snmp_oid)) {
return $snmp_return;
} else {
show_help("SNMP");
}
} else {
if ($snmp_version == "2c" || $snmp_version == "2") {
if ($snmp_return = @snmp2_walk($snmp_host, $snmp_community, $snmp_oid)) {
return $snmp_return;
} else {
show_help("SNMP");
}
} else {
show_help("SNMP");
}
}
} else {
show_help("SNMP_MODULE");
}
}
示例6: snmpwalk
<?php
$host = '10.255.255.247';
$community = 'cf-read';
$object_id = 'IF-MIB::ifDescr';
$object_id1 = 'IF-MIB::ifInOctets';
$sysdesc = snmpwalk($host, $community, $object_id1);
$t1 = microtime(true);
sleep(1);
$sysdesc1 = snmpwalk($host, $community, $object_id1);
$t2 = microtime(true);
echo '耗时' . round($t2 - $t1, 3) . '秒';
$oid = snmpwalk($host, $community, $object_id);
echo $sysdesc1[5] . '\\n' . $sysdesc[5];
print_r((format($sysdesc1[5]) - format($sysdesc[5])) * 8 / 1024 / 1024);
print_r($oid[5]);
function format($result)
{
if (!$result) {
return false;
}
if (is_array($result)) {
$result = array_shift($result);
}
$result = str_replace('STRING: ', '', $result);
$result = str_replace('INTEGER: ', '', $result);
$result = str_replace('Counter32: ', '', $result);
$result = str_replace('Gauge32: ', '', $result);
return $result;
}
//$a = snmpwalkoid("127.0.0.1", "public", "");
示例7: str_ireplace
$swImage2UpdateDate_only = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.10.94.89.89.2.16.1.1.7.1", $timeout, $retries);
$swImage2UpdateDate_only = str_ireplace(chr(34), '', $swImage2UpdateDate_only);
$swImage2UpdateDate_only = trim($swImage2UpdateDate_only);
$swImage2UpdateTime_only = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.10.94.89.89.2.16.1.1.9.1", $timeout, $retries);
$swImage2UpdateTime_only = str_ireplace(chr(34), '', $swImage2UpdateTime_only);
$swImage2UpdateTime_only = trim($swImage2UpdateTime_only);
$swImage2UpdateTime = $swImage2UpdateDate_only . ' ' . $swImage2UpdateTime_only;
// Пользователь, обновивший прошивку 1
$swImage1SendUser = '';
// Пользователь, обновивший прошивку 2
$swImage2SendUser = '';
}
//Блок описания коммутатора для 3026
if ($ModelType == 'DES-3026') {
//Root Port для 3026 (может и не найтись)
$swRootPort = @snmpwalk($ip, $rcomm, ".1.3.6.1.4.1.171.11." . $p_oid[$ModelType] . ".2.16.4.1.4", $timeout, $retries);
//Собственно поиск Root порта
for ($pi = 0; $pi < $portscount[$ModelType]; $pi++) {
if ($swRootPort[$pi] == 4) {
$sysRootPort = $pi + 1;
}
}
if ($sysRootPort == "") {
$sysRootPort = "None";
}
//Определение MAC-адреса устройства
$swIfIndex = @snmpget($ip, $rcomm, ".1.3.6.1.2.1.4.20.1.2." . $ip, $timeout, $retries);
$sysMACaddr = @snmpget($ip, $rcomm, ".1.3.6.1.2.1.4.22.1.2." . $swIfIndex . "." . $ip, $timeout, $retries);
$sysMACaddr = str_ireplace(chr(34), '', $sysMACaddr);
$sysMACaddr = trim($sysMACaddr);
$sysMACaddr = str_replace(' ', ':', $sysMACaddr);
示例8: WIFI_GetAllSignal
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;
}
示例9: session_start
<?php
/**
Consulta o status da CPU para o I.P da sessão e retorna no formato para ser lido pelo gráfico.
*/
session_start();
$ip = $_SESSION["ip"];
$cpu_used = snmpwalk($ip, "public", "1.3.6.1.2.1.25.3.3.1");
preg_match_all('!\\d+!', $cpu_used[1], $matches);
//somente numeros
$var = implode(' ', $matches[0]);
//copiadoarray para variavl
echo "&label=" . date('H:i:s') . "&value=" . $var;
示例10: mysql_query
}
if (empty($_GET['i'])) {
$i = 'empty';
} else {
$i = $_GET['i'];
}
$result = mysql_query("SELECT * FROM hosts WHERE host like '%{$q}%'");
while ($row = mysql_fetch_array($result)) {
$ip = $row['ip'];
$s = $row['ifdescr'];
}
$result1 = mysql_query("SELECT * FROM hosts WHERE host like'%{$q}%' and idinterface ='{$i}'");
$community = 'public';
$outoctets = snmpwalk("{$ip}", "{$community}", "1.3.6.1.2.1.2.2.1.16");
$inoctets = snmpwalk("{$ip}", "{$community}", "1.3.6.1.2.1.2.2.1.10");
$interf = snmpwalk("{$ip}", "{$community}", "1.3.6.1.2.1.2.2.1.8");
while ($row1 = mysql_fetch_array($result1)) {
//$interf=$row1['ifoperstatus'];
//$inoctets=$row1['inoctets'];
//$outoctets=$row1['outoctets'];
$ifdescr = $row1['ifdescr'];
}
$inoctets1 = substr($inoctets[$i], 10, 17);
$outoctets1 = substr($outoctets[$i], 10, 17);
$ifdescr1 = substr($ifdescr, 7, 17);
$interf1 = substr($interf[$i], 8, -3);
$inmbps = (int) ($inoctets1 / 1048576) * 8;
$outmbps = (int) ($outoctets1 / 1048576) * 8;
$ingps = $inmbps / 1024;
$ingps1 = $outmbps / 1024;
?>
示例11: walk
/**
* Function walks through SNMP object id and returns result in array,
* or returns false of call failed
*
* @param string $snmpObjectId
* @return array
* @throws Exception if IP address is not set
* @throws Exception if $snmpObjectId is not in string format
*/
public function walk($snmpObjectId)
{
/**
* Check if IP address is set
*/
if ($this->ip === null) {
require_once 'Exception.php';
throw new Kohut_SNMP_Exception('IP address was not set.');
}
/**
* Check if SNMP object ID is in string format
*/
if (!is_string($snmpObjectId)) {
require_once 'Exception.php';
throw new Kohut_SNMP_Exception('SNMP Object ID is not string.');
}
return @snmpwalk($this->ip, 'public', $snmpObjectId, $this->maxTimeout);
}
示例12: _sGetCpuInfo
private function _sGetCpuInfo($sIp)
{
$cpuinfo = array();
$ret = snmpwalk($sIp, $this->_aConf['community'], 'hrDeviceEntry', 300000);
if (is_array($ret)) {
$len = 0;
foreach ($ret as $k => $v) {
list($t, $s) = explode(':', $v);
if ('INTEGER' !== $t) {
$len = $k;
break;
}
}
for ($i = 0; $i < $len; $i++) {
list($t, $s) = explode(':', $ret[$len + $i], 2);
if (' HOST-RESOURCES-TYPES::hrDeviceProcessor' == $s) {
list($t, $s) = explode(':', $ret[2 * $len + $i], 2);
$cpuinfo[trim($s)]++;
}
}
}
$ret = array();
foreach ($cpuinfo as $k => $v) {
$ret[] = $v . '个逻辑CPU,' . $k;
}
return implode(' || ', $ret);
}
示例13: getTree
/**
* Do snmpwalk
*
* @param unknown_type $rootOID
* @return array Array of values
*/
public function getTree($rootOID = null)
{
$retval = @snmpwalk("{$this->host}:{$this->port}", $this->community, $rootOID, $this->timeout);
return $retval;
}
示例14: _walkget
/**
* @access private
*/
function _walkget($oid)
{
$ret = snmpwalk($this->host, $this->community, $oid);
if (sizeof($ret) > 0) {
return $ret[0];
} else {
return false;
}
}
示例15: my_snmp_walk
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;
}