summaryrefslogtreecommitdiffstats
path: root/libs/network.php
diff options
context:
space:
mode:
authorShevAbam <shevabam@gmail.com>2014-06-18 10:11:11 +0200
committerShevAbam <shevabam@gmail.com>2014-06-18 10:11:11 +0200
commit20705a550df5b13a544dc0865c6aef16e64c99d9 (patch)
treee396dface41e30d39a68d5fe66097b1f8f641a81 /libs/network.php
+ First commit (version 2.0)v2.0
Diffstat (limited to 'libs/network.php')
-rw-r--r--libs/network.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/libs/network.php b/libs/network.php
new file mode 100644
index 0000000..12521bf
--- /dev/null
+++ b/libs/network.php
@@ -0,0 +1,32 @@
+<?php
+require 'Utils/Misc.class.php';
+
+$datas = array();
+
+if (!(exec('/sbin/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 $key => $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);
+
+ $datas[] = array(
+ 'interface' => $interface,
+ 'ip' => $getIps[$key],
+ 'transmit' => Misc::getSize($getBandwidth_tx[0]),
+ 'receive' => Misc::getSize($getBandwidth_rx[0]),
+ );
+
+ unset($getBandwidth_tx, $getBandwidth_rx);
+ }
+}
+
+
+echo json_encode($datas); \ No newline at end of file