summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/etc/inc/util.inc25
-rw-r--r--src/usr/local/www/services_dhcp_edit.php16
2 files changed, 18 insertions, 23 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc
index 8d8a083..418ad51 100644
--- a/src/etc/inc/util.inc
+++ b/src/etc/inc/util.inc
@@ -1848,22 +1848,25 @@ function alias_expand_urltable($name) {
return null;
}
-/* obtain MAC address given an IP address by looking at the ARP table */
+/* obtain MAC address given an IP address by looking at the ARP/NDP table */
function arp_get_mac_by_ip($ip) {
- mwexec("/sbin/ping -c 1 -t 1 " . escapeshellarg($ip), true);
- $arpoutput = "";
- exec("/usr/sbin/arp -n " . escapeshellarg($ip), $arpoutput);
-
- if ($arpoutput[0]) {
- $arpi = explode(" ", $arpoutput[0]);
- $macaddr = $arpi[3];
+ unset($arp_ndp_output);
+ switch (is_ipaddr($ip)) {
+ case 4:
+ mwexec("/sbin/ping -c 1 -t 1 " . escapeshellarg($ip), true);
+ exec("/usr/sbin/arp -n " . escapeshellarg($ip) . " | /usr/bin/awk '{print $4}'", $arp_ndp_output);
+ break;
+ case 6:
+ mwexec("/sbin/ping6 -c 1 -X 1 " . escapeshellarg($ip), true);
+ exec("/usr/sbin/ndp -n " . escapeshellarg($ip) . " | /usr/bin/tail -n+2 | /usr/bin/awk '{print $2}'", $arp_ndp_output);
+ break;
+ }
+ if ($arp_ndp_output[0]) {
+ $macaddr = $arp_ndp_output[0];
if (is_macaddr($macaddr)) {
return $macaddr;
- } else {
- return false;
}
}
-
return false;
}
diff --git a/src/usr/local/www/services_dhcp_edit.php b/src/usr/local/www/services_dhcp_edit.php
index 02ac9d9..22bfbcf 100644
--- a/src/usr/local/www/services_dhcp_edit.php
+++ b/src/usr/local/www/services_dhcp_edit.php
@@ -405,18 +405,8 @@ if ($_POST) {
// Get our MAC address
$ip = $_SERVER['REMOTE_ADDR'];
-switch (is_ipaddr($ip)) {
- case 4:
- $mymac = exec("/usr/sbin/arp -an | grep '('{$ip}')' | head -n 1 | cut -d' ' -f4");
- $mymac = str_replace("\n", "", $mymac);
- break;
- case 6:
- $mymac = exec("/usr/sbin/ndp -na | /usr/bin/grep '{$ip}' | /usr/bin/head -n 1 | /usr/bin/awk '{ print $2 }'");
- $mymac = str_replace("\n", "", $mymac);
- break;
- default:
- unset($mymac);
-}
+unset($mymac);
+$mymac = arp_get_mac_by_ip($ip);
$iflist = get_configured_interface_with_descr();
$ifname = '';
@@ -444,6 +434,7 @@ $macaddress = new Form_Input(
$pconfig['mac'],
['placeholder' => 'xx:xx:xx:xx:xx:xx']
);
+
$btnmymac = new Form_Button(
'btnmymac',
'Copy My MAC',
@@ -452,6 +443,7 @@ $btnmymac = new Form_Button(
);
$btnmymac->setAttribute('type','button')->removeClass('btn-primary')->addClass('btn-success btn-sm');
+
$group = new Form_Group('MAC Address');
$group->add($macaddress);
if (!empty($mymac)) {
OpenPOWER on IntegriCloud