©
本文档使用
php.cn手册 发布
(PHP 4, PHP 5)
snmpwalkoid — 查询关于网络实体的信息树
$hostname
, string $community
, string $object_id
[, int $timeout
[, int $retries
]] )
返回一个包含对象 id 及它们各自对象值的关联数组,这些对象以
object_id
作为根,错误则返回 FALSE
。
snmpwalkoid() 用于从
hostname
所指定的 SNMP
代理那里读取所有对象 id 及它们各自的值。community
指定对于该代理有读权限的域。一个为 NULL
的 object_id
将被看作
SNMP 对象树的根,而在此树下的所有对象将作为一个数组被返回。如果指定了
object_id
,则返回所有在
object_id
下的 SNMP 对象。
snmpwalkoid() 和 snmpwalk() 的同时存在出于历史原因。提供两个函数是为了向后兼容。
<?php
$a = snmpwalkoid ( "127.0.0.1" , "public" , "" );
?>
上边的函数调用将从运行于本机的 SNMP 代理那里返回所有的 SNMP 对象。可使用循环遍历这些值。
<?php
for ( reset ( $a ); $i = key ( $a ); next ( $a )) {
echo " $i : $a [ $i ] <br />\n" ;
}
?>
[#1] Anonymous [2014-11-21 22:00:23]
make sure you install "snmp-mibs-downloader" in debian.
apt-get install snmp-mibs-downloader
you my also need to edit your /etc/apt/sources.list
deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
[#2] thammer at rtccom dot com [2005-06-14 08:29:20]
The above note mentions that the MAC addresses come back converted to integers or something funky like that. Not sure why that is happening but I fixed that with a wrapper function.
function PadMAC($mac) {
$mac_arr = explode(':',$mac);
foreach($mac_arr as $atom) {
$atom = trim($atom);
$newarr[] = sprintf("%02s",$atom);
}
$newmac = implode(':',$newarr);
return $newmac;
}
Maybe that will help somebody with that issue. I know I personally use the heck out of these user contributed notes
[#3] gene_wood at example dot com [2004-10-14 09:23:49]
Looks like timeout is in MICRO seconds.
1,000,000 µs = 1 s
[#4] jasper at pointless dot net [2001-01-06 19:21:32]
N.B. it's possible for snmpwalkoid to lose data - the "rmon.matrix.matrixSDTable" table for example uses binary mac addresses as part of the index, these get converted to ascii, and by the time they get to php they can be non-unique - so some entrys in the table get lost...