PHP 8.3.0 RC 6 available for testing

snmpwalkoid

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

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

说明

snmpwalkoid(
    string $hostname,
    string $community,
    array|string $object_id,
    int $timeout = -1,
    int $retries = -1
): array|false

snmpwalkoid() 函数用于从 hostname 指定的 SNMP 代理读取所有对象 ID 及其各自的值。

snmpwalkoid()snmpwalk() 的存在是有历史原因的。提供这两个函数是为了向后兼容。请改用 snmprealwalk()

参数

hostname

SNMP 代理。

community

The read community.

object_id

如果为 null,则将 object_id 作为 SNMP 对象树的根,并且该树下的所有对象都作为数组返回。

如果指定了 object_id,则返回该 object_id 下面的所有 SNMP 对象。

timeout

第一次超时前的微秒数。

retries

发生超时时重试的次数。

返回值

返回关联数组,其中包含对象 ID 及其各自的对象值,从 object_id 开始为 root 或错误时为 false

示例

示例 #1 snmpwalkoid() 示例

<?php
$a
= snmpwalkoid("127.0.0.1", "public", "");
for (
reset($a); $i = key($a); next($a)) {
echo
"$i: $a[$i]<br />\n";
}
?>

上面的函数调用将从本地主机上运行的 SNMP 代理返回所有 SNMP 对象。可以通过循环遍历这些值

参见

add a note

User Contributed Notes 4 notes

up
0
Anonymous
8 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
18 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
19 years ago
Looks like timeout is in MICRO seconds.
1,000,000 &micros = 1 s
up
0
jasper at pointless dot net
22 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