qq lignes de php pour lire /proc/net/dev
// ---------------------------------
function stat_reseau()
{
$results = array();
if ( $fd = fopen("/proc/net/dev", "r" ) ) {
while ( $buf = fgets($fd, 4096)) {
if ( preg_match( "/", $buf ) ) {
list( $dev_nom, $stats_list ) = preg_split( "/", $buf, 2 );
$stats = preg_split( "/\s+/", trim($stats_list) );
$results[$dev_nom] = array();
$results[$dev_nom]['recu_bytes'] = $stats[0];
$results[$dev_nom]['recu_packets'] = $stats[1];
$results[$dev_nom]['recu_errs'] = $stats[2];
$results[$dev_nom]['recu_drop'] = $stats[3];
$results[$dev_nom]['envoye_bytes'] = $stats[8];
$results[$dev_nom]['envoye_packets'] = $stats[9];
$results[$dev_nom]['envoye_errs'] = $stats[10];
$results[$dev_nom]['envoye_drop'] = $stats[11];
$results[$dev_nom]['errs'] = $stats[2] + $stats[10];
$results[$dev_nom]['drop'] = $stats[3] + $stats[11];
}
}
}
return $results;
}
// recup du tableau
$net = stat_reseau();
// decomposition et tout ce qu'on veut ...
while ( list($dev,$stat) = each($net) ) {
$dev = trim($dev);
if ($dev == "lo" ) continue;
if ($dev == "ppp0" ) {
get_bytes += $stat['recu_bytes'];
send_bytes += $stat['envoye_bytes'];
}
.........
..........
etc ...
---------------
Do androïds dream of electric sheep ?