array( '814'=>'mtenstatisticTable.htm', '624'=>'RST_stattbl.htm'), 'logout'=>array( '814'=>'logout.htm', '624'=>'LGO_logout.htm') ); $stats = array(); $err_count = 0; $today = date("d-m-Y/H:i:s"); file_get_contents("http://$username:$password@$gateway_host/"); # get an initial auth do { $file = file_get_contents("http://$username:$password@$gateway_host/{$filenames['stats'][$model]}"); if ($file == '') { sleep(3); $err_count++; } } while ($file == '' && $err_count < 5); if ($err_count < 5) { if (!preg_match('/(.*?)<\/table>/si',$file,$table)) die("\n\n# Can\'t stats table. Is someone else logged into the admin interface?\n"); $cells = preg_split('/<\/td>/i',$table[1]); foreach ($cells as $key=>$value) { $cells[$key] = trim(strip_tags($value)); } array_pop($cells); // just cuz $stats = array( 'WAN' => array( 'TxPacks' => $cells[10], 'RxPacks' => $cells[11], 'Collisions' => $cells[12], 'TxBps' => $cells[13], 'RxBps' => $cells[14], 'Uptime' => $cells[15] ), 'LAN' => array( 'TxPacks' => $cells[18], 'RxPacks' => $cells[19], 'Collisions' => $cells[20], 'TxBps' => $cells[21], 'RxBps' => $cells[22], 'Uptime' => $cells[23] ), 'WLAN' => array( 'TxPacks' => $cells[25], 'RxPacks' => $cells[26], 'Collisions' => $cells[27], 'TxBps' => $cells[28], 'RxBps' => $cells[29], 'Uptime' => $cells[30] ) ); $output = $stats[$network]['TxBps']."\n".$stats[$network]['RxBps']."\n\n{$network}_bandwidth\n"; print $output; file_get_contents("http://$username:$password@$gateway_host/{$filenames['logout'][$model]}"); // Logout afterwards to free up the admin interface } else { print "## Too many errors\n## Did you specify the correct model?\n"; } ?>