summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorShevAbam <shevabam@gmail.com>2014-11-11 18:37:32 +0100
committerShevAbam <shevabam@gmail.com>2014-11-11 18:37:32 +0100
commit258e0edbaad8e767060fa224c37f6594fea715a2 (patch)
tree2a0d96a9e234da509c12c0ae18ec3c2e1948d17c /libs
parentf71fb5bfc125171a9c170f4f1cec5b8ba601eaf0 (diff)
Network : fix for ifconfig command and for getting network ratesv2.3
Diffstat (limited to 'libs')
-rw-r--r--libs/network.php31
1 files changed, 23 insertions, 8 deletions
diff --git a/libs/network.php b/libs/network.php
index e486fc5..20b5a3a 100644
--- a/libs/network.php
+++ b/libs/network.php
@@ -1,25 +1,40 @@
<?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');
}
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);
+
+ if (!isset($ip[0]))
+ $ip[0] = '';
+
+ $network[] = array(
+ 'name' => $name,
+ 'ip' => $ip[0],
+ );
+ }
- foreach ($getInterfaces as $key => $interface)
+ foreach ($network as $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.'/statistics/rx_bytes', $getBandwidth_rx);
+ exec('cat /sys/class/net/'.$interface['name'].'/statistics/tx_bytes', $getBandwidth_tx);
+ exec('cat /sys/class/net/'.$interface['name'].'/statistics/rx_bytes', $getBandwidth_rx);
$datas[] = array(
- 'interface' => $interface,
- 'ip' => $getIps[$key],
+ 'interface' => $interface['name'],
+ 'ip' => $interface['ip'],
'transmit' => Misc::getSize($getBandwidth_tx[0]),
'receive' => Misc::getSize($getBandwidth_rx[0]),
);