ScotlandPHP

snmpwalkoid

(PHP 4, PHP 5, PHP 7)

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

说明

array snmpwalkoid ( string $hostname , string $community , string $object_id [, int $timeout [, int $retries ]] )

返回一个包含对象 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";
}
?>

add a note add a note

User Contributed Notes 4 notes

up
0
Anonymous
2 years ago
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
up
0
thammer at rtccom dot com
12 years ago
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
up
0
gene_wood at example dot com
13 years ago
Looks like timeout is in MICRO seconds.
1,000,000 &micros = 1 s
up
0
jasper at pointless dot net
16 years ago
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...
To Top