mirror of
https://github.com/ShaYmez/ezservermonitor-web.git
synced 2025-08-16 11:42:33 -04:00
Network : fix for ifconfig command and for getting network rates
This commit is contained in:
parent
f71fb5bfc1
commit
258e0edbaa
@ -1,25 +1,40 @@
|
|||||||
<?php
|
<?php
|
||||||
require 'Utils/Misc.class.php';
|
require 'Utils/Misc.class.php';
|
||||||
|
|
||||||
$datas = array();
|
$datas = array();
|
||||||
|
$network = array();
|
||||||
|
|
||||||
if (!(exec('/sbin/ifconfig |awk -F \'[/ |: ]\' \'{print $1}\' |sed -e \'/^$/d\'', $getInterfaces)))
|
$ifconfig = trim(shell_exec('which ifconfig'));
|
||||||
|
|
||||||
|
if (!(exec($ifconfig.' |awk -F \'[/ |: ]\' \'{print $1}\' |sed -e \'/^$/d\'', $getInterfaces)))
|
||||||
{
|
{
|
||||||
$datas[] = array('interface' => 'N.A', 'ip' => 'N.A');
|
$datas[] = array('interface' => 'N.A', 'ip' => 'N.A');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
exec('/sbin/ifconfig | awk \'/inet / {print $2}\' | cut -d \':\' -f2', $getIps);
|
foreach ($getInterfaces as $name)
|
||||||
|
{
|
||||||
|
$ip = null;
|
||||||
|
exec($ifconfig.' '.$name.' | awk \'/inet / {print $2}\' | cut -d \':\' -f2', $ip);
|
||||||
|
|
||||||
foreach ($getInterfaces as $key => $interface)
|
if (!isset($ip[0]))
|
||||||
|
$ip[0] = '';
|
||||||
|
|
||||||
|
$network[] = array(
|
||||||
|
'name' => $name,
|
||||||
|
'ip' => $ip[0],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($network as $interface)
|
||||||
{
|
{
|
||||||
// Get transmit and receive datas by interface
|
// Get transmit and receive datas by interface
|
||||||
exec('cat /sys/class/net/'.$interface.'/statistics/tx_bytes', $getBandwidth_tx);
|
exec('cat /sys/class/net/'.$interface['name'].'/statistics/tx_bytes', $getBandwidth_tx);
|
||||||
exec('cat /sys/class/net/'.$interface.'/statistics/rx_bytes', $getBandwidth_rx);
|
exec('cat /sys/class/net/'.$interface['name'].'/statistics/rx_bytes', $getBandwidth_rx);
|
||||||
|
|
||||||
$datas[] = array(
|
$datas[] = array(
|
||||||
'interface' => $interface,
|
'interface' => $interface['name'],
|
||||||
'ip' => $getIps[$key],
|
'ip' => $interface['ip'],
|
||||||
'transmit' => Misc::getSize($getBandwidth_tx[0]),
|
'transmit' => Misc::getSize($getBandwidth_tx[0]),
|
||||||
'receive' => Misc::getSize($getBandwidth_rx[0]),
|
'receive' => Misc::getSize($getBandwidth_rx[0]),
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user