From c16f7c5c983a23839d42e00b250da81689848f51 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 6 Mar 2013 20:47:31 +0545 Subject: Add display by host name to Traffic Graph --- usr/local/www/bandwidth_by_ip.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'usr/local/www') diff --git a/usr/local/www/bandwidth_by_ip.php b/usr/local/www/bandwidth_by_ip.php index 5c46912..979cffb 100755 --- a/usr/local/www/bandwidth_by_ip.php +++ b/usr/local/www/bandwidth_by_ip.php @@ -35,6 +35,25 @@ if ($sort == "out") else {$sort_method = "-R";} +// get the desired format for displaying the host name or IP +$hostipformat = $_GET['hostipformat']; +$iplookup = array(); +// If hostname display is requested and the DNS forwarder does not already have DHCP static names registered, +// then load the DHCP static mappings into an array keyed by IP address. +if (($hostipformat == "hostname") && (!isset($config['dnsmasq']['regdhcpstatic']))) { + if (is_array($config['dhcpd'])) { + foreach ($config['dhcpd'] as $ifdata) { + if (is_array($ifdata['staticmap'])) { + foreach ($ifdata['staticmap'] as $hostent) { + if (($hostent['ipaddr'] != "") && ($hostent['hostname'] != "")) { + $iplookup[$hostent['ipaddr']] = $hostent['hostname']; + } + } + } + } + } +} + $_grb = 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); $someinfo = false; @@ -46,8 +65,22 @@ for ($x=2; $x<12; $x++){ $emptyinfocounter = 1; if ($bandwidthinfo != "") { $infoarray = explode (":",$bandwidthinfo); - //print IP of host; - echo $infoarray[0] . ";" . $infoarray[1] . ";" . $infoarray[2] . "|"; + if ($hostipformat == "hostname") { + $addrdata = gethostbyaddr($infoarray[0]); + if ($addrdata == $infoarray[0]) { + // gethostbyaddr() gave us back the IP address, so try the static mapping array + if ($iplookup[$infoarray[0]] != "") + $addrdata = $iplookup[$infoarray[0]]; + } else { + // gethostbyaddr() gave an answer. Just pass back the name up to the first "." + $name_array = explode(".", $addrdata); + $addrdata = $name_array[0]; + } + } else { + $addrdata = $infoarray[0]; + } + //print host information; + echo $addrdata . ";" . $infoarray[1] . ";" . $infoarray[2] . "|"; //mark that we collected information $someinfo = true; -- cgit v1.1