• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • snmpwalkoid()

    (PHP 4, PHP 5, PHP 7)

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

    说明

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

    返回一个包含对象 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";
    }
    ?>
    
    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
    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
    Looks like timeout is in MICRO seconds.
    1,000,000 &micros = 1 s
    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...

    上篇:snmpwalk()

    下篇:SNMP::close()