snmpwalkoid

(PHP 4, PHP 5, PHP 7, PHP 8)

snmpwalkoid查询关于网络实体的信息树

说明

snmpwalkoid ( string $hostname , string $community , string $object_id , int $timeout = ? , int $retries = ? ) : array

返回一个包含对象 id 及它们各自对象值的关联数组,这些对象以 object_id 作为根,错误则返回 false

snmpwalkoid() 用于从 hostname 所指定的 SNMP 代理那里读取所有对象 id 及它们各自的值。community 指定对于该代理有读权限的域。一个为 nullobject_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";
}
?>

User Contributed Notes

Anonymous 21-Nov-2014 10:00
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
thammer at rtccom dot com 14-Jun-2005 08:29
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
gene_wood at example dot com 14-Oct-2004 09:23
Looks like timeout is in MICRO seconds.
1,000,000 &micros = 1 s
jasper at pointless dot net 06-Jan-2001 07:21
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...