PHP 7.1.20 Released


(PHP 4, PHP 5, PHP 7)

snmpwalkReçoit tous les objets SNMP d'un agent


array snmpwalk ( string $hostname , string $community , string $object_id [, int $timeout = 1000000 [, int $retries = 5 ]] )

snmpwalk() est utilisé pour lire toutes les valeurs d'un agent SNMP spécifié par hostname.

Liste de paramètres


L'agent SNMP (serveur).


La communauté de lecture.


Si NULL, object_id est pris comme racine des objets SNMP et tous les objets de cet arbre sont retournés sous la forme d'un tableau.

Si object_id est spécifié, tous les objets SNMP suivant cet object_id sont retournés.


Le nombre de microsecondes depuis le premier timeout.


Le nombre de tentative dans le cas où le délai d'expiration survient.

Valeurs de retour

Retourne un tableau de valeurs de l'objet SNMP, en commençant par object_id ou FALSE si une erreur survient.


Exemple #1 Exemple avec snmpwalk()


foreach (
$a as $val) {


L'appel à la fonction ci-dessus retournera tous les objets SNMP depuis l'agent SNMP exécuté sur l'hôte local. On parcourt les valeurs via une boucle.

Voir aussi

  • snmprealwalk() - Retourne tous les objets, y compris les identifiants respectifs inclus dans l'objet

add a note add a note

User Contributed Notes 9 notes

steve at ourabode dot org
16 years ago
Timeout is in MICRO seconds.
1,000,000 &micros = 1 s
Lars Troen
15 years ago
Note that there's different behaviuor in php snmpwalk and ucd snmpwalk. If you try to walk an oid that has one value not under a subkey of the walked oid, ucd snmpwalk will return the value while php's snmpwalk will not.
anders at ei dot nu
15 years ago
It would be nice to be able to specify what snmp version to use ( 1,2c,3 )

For now, I'ts hardcoded in ext/snmp/snmp.c

change session.version from 1 to 2c or 3 if you need for now..


session.version = SNMP_VERSION_1;

session.version = SNMP_VERSION_2c;
layer2 at www dot com
16 years ago
Something to care about in dealing with snmpwalk:<BR>
While walking the MIB, snmpwalk puts info that gets into an array, and that is correct.<BR>
The trouble happened when snmpwalk needs to collect information from instances that contains subinstances (i.e. walking . and having instances like 1.1, 1.2, 1.3): in this case it gets info and passes into an array, but when walking the array, each value is preceeded by 'Counter32: '.<BR>
I've tested this in many ways and it always happened the same way.
john at antefacto dot com
16 years ago
Ah. That's why all of our SNMP stuff was timing out anytime there was any load on the system. Sigh. A waste of two weeks trying to debug snmp....

Even the snmpcmd manpage doesn't give a
unit for timeout.
billf at freebsd dot org
16 years ago
for the poster wondering what the
timeout field was measured in:

from the ucd-snmp header file snmp_api.h:

    long    timeout;
    /* Number of uS until first timeout
    then exponential backoff */
17 years ago
A quick router device view:

include "header.html";

$host = "auscr1";
$community = "tellme";
$sysDescr = snmpget("$host","$community","system.sysDescr.0");
$ifDescr = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifDescr");
$ifIndex = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifIndex");
$ifAdminStatus = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifAdminStatus");
$ifOperStatus = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifOperStatus");
$ifLastChange = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifLastChange");
print "<table border=1 bgcolor=#ffffff><tr><td>$host</td></tr></table><br>";
print "<table border=1 bgcolor=#ffffff><tr><td>$sysDescr</td></tr></table><br>";
print "<table border=1 bgcolor=#ffffff>";
print "<tr>
for ($i=0; $i<count($ifIndex); $i++) {
        print "<tr>";
        print "<td>$ifIndex[$i]</td>";
        print "<td>$ifDescr[$i]</td>";
        print "<td>$ifAdminStatus[$i]</td>";
        print "<td>$ifOperStatus[$i]</td>";
        print "<td>$ifLastChange[$i]</td>";
        print "</tr>";
print "</table>";

bobby [dot] clark [at] eku [dot] edu
14 years ago
I had to use an object_id like these.

= '';
$community = 'public';
$object_id = 'IF-MIB::interfaces.ifTables.ifEntry.ifAdminStatus';

$sysdesc = snmpwalk($host, $community', $object_id);
13 years ago
I found on Windows (PHP 5) an empty string did not return anything, it just timed out.  I had to use null instead:

= snmpwalk("", "public", null);
To Top