From 6624a6befcb027d15e122fe19441002cbcf675bf Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Mon, 3 Jun 2019 15:23:39 -0300 Subject: [PATCH] Use system_get_arp_table() --- src/usr/local/www/diag_arp.php | 68 +++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/src/usr/local/www/diag_arp.php b/src/usr/local/www/diag_arp.php index c72ce7e049..2fd94c0c18 100644 --- a/src/usr/local/www/diag_arp.php +++ b/src/usr/local/www/diag_arp.php @@ -198,7 +198,7 @@ foreach ($leases as $value) { $dhcpip[$value['ip']] = $value['hostname']; } -exec("/usr/sbin/arp -an", $rawdata); +$arp_table = system_get_arp_table(); $i = 0; @@ -212,18 +212,6 @@ foreach ($ifdescrs as $key => $interface) { } } -$data = array(); -foreach ($rawdata as $line) { - $elements = explode(' ', $line, 7); - $arpent = array(); - $arpent['ip'] = trim(str_replace(array('(', ')'), '', $elements[1])); - $arpent['mac'] = trim($elements[3]); - $arpent['interface'] = trim($elements[5]); - $arpent['status'] = trim(substr($elements[6], 0, strrpos($elements[6], ' '))); - $arpent['linktype'] = trim(str_replace(array('[', ']'), '', strrchr($elements[6], ' '))); - $data[] = $arpent; -} - function _getHostName($mac, $ip) { global $dhcpmac, $dhcpip; @@ -277,9 +265,10 @@ if ($dns == "") { } } -foreach ($data as &$entry) { - if ($dnsavailable) { - $dns = trim(_getHostName($entry['mac'], $entry['ip'])); +foreach ($arp_table as &$entry) { + if ($dnsavailable && !empty($entry['mac-address'])) { + $dns = trim(_getHostName($entry['mac-address'], + $entry['ip-address'])); } else { $dns=""; } @@ -292,7 +281,7 @@ foreach ($data as &$entry) { unset($entry); // Sort the data alpha first -$data = msort($data, "dnsresolve"); +$arp_table = msort($arp_table, "dnsresolve"); // Load MAC-Manufacturer table $mac_man = load_mac_manufacturer_table(); @@ -317,29 +306,48 @@ $mac_man = load_mac_manufacturer_table(); + foreach ($arp_table as $entry): ?> - - - - +{$mac}"; + } else { + $mac = trim($entry['mac-address']); + print "{$mac}"; + $mac_hi = strtoupper($mac[0] . $mac[1] . + $mac[3] . $mac[4] . $mac[6] . + $mac[7]); if (isset($mac_man[$mac_hi])) { - print '('. $mac_man[$mac_hi] .')'; + print '('. + $mac_man[$mac_hi] . + ')'; } - ?> + } + + $status = ''; + if (!empty($entry['expires'])) { + $status = sprintf(gettext( + "Expires in %d seconds"), + $entry['expires']); + } else if (!empty($entry['permanent'])) { + $status = gettext("Permanent"); + } +?> - - + + - + - +