summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlukehamburg <luke.hamburg@gmail.com>2017-02-08 03:13:08 -0500
committerRenato Botelho <renato@netgate.com>2017-02-10 15:57:52 -0200
commit307243e7b7cb88283740ae29a2d6150cc59bc573 (patch)
tree857b98cc5c1aa9674f10939b9b8c13c50f4db164
parent9a20d17098ee74a96370aeeb0fd9a1fcf7f8d86c (diff)
downloadpfsense-307243e7b7cb88283740ae29a2d6150cc59bc573.zip
pfsense-307243e7b7cb88283740ae29a2d6150cc59bc573.tar.gz
2nd try. . .
/etc/inc/util.inc: - arp_get_mac_by_ip() updated to support IPv6 - attempt at code streamline /usr/local/www/services_dhcp_edit.php: - streamline code, now just a simple call to arp_get_mac_by_ip() (cherry picked from commit dd83f869b79a858bd74c7a8bb4adcd49217445b0)
-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