summaryrefslogtreecommitdiffstats
path: root/usr/local/www/bandwidth_by_ip.php
diff options
context:
space:
mode:
Diffstat (limited to 'usr/local/www/bandwidth_by_ip.php')
-rwxr-xr-xusr/local/www/bandwidth_by_ip.php25
1 files changed, 19 insertions, 6 deletions
diff --git a/usr/local/www/bandwidth_by_ip.php b/usr/local/www/bandwidth_by_ip.php
index 71e4c27..ada7209 100755
--- a/usr/local/www/bandwidth_by_ip.php
+++ b/usr/local/www/bandwidth_by_ip.php
@@ -22,12 +22,25 @@ $interface = $_GET['if'];
$real_interface = convert_friendly_interface_to_real_interface_name($interface);
$intip = find_interface_ip($real_interface);
$intip = explode (".", $intip);
-
-//use class A subnet to make sure we capture all traffic on specified interface
-$intsubnet = $intip[0] . ".0.0.0/8";
-
-exec("/usr/local/bin/rate -i {$real_interface} -nlq 1 -Aba 20 -c {$intsubnet} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1, $2, $4, $6, $8 }'", $listedIPs);
-
+//get interface netmask
+$netmask = find_interface_subnet($real_interface);
+//get the sort method
+$sort = $_GET['sort'];
+if ($sort == "out")
+ {$sort_method = "-T";}
+else
+ {$sort_method = "-R";}
+//use the same class of the specified interface
+if ($netmask >= 24) {
+ $intsubnet = $intip[0] . "." . $intip[1] . "." . $intip[2] . ".0/24";
+}
+elseif ($netmask >=16){
+ $intsubnet = $intip[0] . "." . $intip[1] . ".0.0/16";
+}
+else {
+ $intsubnet = $intip[0] . ".0.0.0/8";
+}
+exec("/usr/local/bin/rate -i {$real_interface} -nlq 1 -Aba 20 {$sort_method} -c {$intsubnet} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1, $2, $4, $6, $8 }'", $listedIPs);
unset($bandwidthinfo);
unset($receivebytesarray);
unset($transmitbytesarray);
OpenPOWER on IntegriCloud