Revision c16f7c5c
Added by Phil Davis over 12 years ago
usr/local/www/bandwidth_by_ip.php | ||
---|---|---|
35 | 35 |
else |
36 | 36 |
{$sort_method = "-R";} |
37 | 37 |
|
38 |
// get the desired format for displaying the host name or IP |
|
39 |
$hostipformat = $_GET['hostipformat']; |
|
40 |
$iplookup = array(); |
|
41 |
// If hostname display is requested and the DNS forwarder does not already have DHCP static names registered, |
|
42 |
// then load the DHCP static mappings into an array keyed by IP address. |
|
43 |
if (($hostipformat == "hostname") && (!isset($config['dnsmasq']['regdhcpstatic']))) { |
|
44 |
if (is_array($config['dhcpd'])) { |
|
45 |
foreach ($config['dhcpd'] as $ifdata) { |
|
46 |
if (is_array($ifdata['staticmap'])) { |
|
47 |
foreach ($ifdata['staticmap'] as $hostent) { |
|
48 |
if (($hostent['ipaddr'] != "") && ($hostent['hostname'] != "")) { |
|
49 |
$iplookup[$hostent['ipaddr']] = $hostent['hostname']; |
|
50 |
} |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
38 | 57 |
$_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); |
39 | 58 |
|
40 | 59 |
$someinfo = false; |
... | ... | |
46 | 65 |
$emptyinfocounter = 1; |
47 | 66 |
if ($bandwidthinfo != "") { |
48 | 67 |
$infoarray = explode (":",$bandwidthinfo); |
49 |
//print IP of host; |
|
50 |
echo $infoarray[0] . ";" . $infoarray[1] . ";" . $infoarray[2] . "|"; |
|
68 |
if ($hostipformat == "hostname") { |
|
69 |
$addrdata = gethostbyaddr($infoarray[0]); |
|
70 |
if ($addrdata == $infoarray[0]) { |
|
71 |
// gethostbyaddr() gave us back the IP address, so try the static mapping array |
|
72 |
if ($iplookup[$infoarray[0]] != "") |
|
73 |
$addrdata = $iplookup[$infoarray[0]]; |
|
74 |
} else { |
|
75 |
// gethostbyaddr() gave an answer. Just pass back the name up to the first "." |
|
76 |
$name_array = explode(".", $addrdata); |
|
77 |
$addrdata = $name_array[0]; |
|
78 |
} |
|
79 |
} else { |
|
80 |
$addrdata = $infoarray[0]; |
|
81 |
} |
|
82 |
//print host information; |
|
83 |
echo $addrdata . ";" . $infoarray[1] . ";" . $infoarray[2] . "|"; |
|
51 | 84 |
|
52 | 85 |
//mark that we collected information |
53 | 86 |
$someinfo = true; |
Also available in: Unified diff
Add display by host name to Traffic Graph