#run the external command, break output into lines
$arp=`arp -a $ipAddress`;
$lines=explode("\n", $arp);

#look for the output line describing our IP address
foreach($lines as $line)
   $cols=preg_split('/\s+/', trim($line));
   if ($cols[0]==$ipAddress)
echo $macAddr;

It's not working in server.

  • 1
    the result of 'not working' is not enough for anyone to help: what's not working? – schroeder May 18 '17 at 6:36
  • 3
    Are you aware of how ARP works? The fact that you are asking about both PHP and JS makes it appear that you are unaware that MAC addresses do not get passed to servers on the Internet – schroeder May 18 '17 at 6:37
  • 1
    PHP get executed on server, you will only be able to get server's mac address, not client. And javascript can't access system things so you won't get mac address, and by the way, what would you do with a client's mac address ? Unless you can be "phyisically" (LAN/VLAN) on the same network it's uterly useless. – Walfrat May 18 '17 at 7:21
  • I dont have the rep to mark it myself. But I consider this a duplicate of this question – Snappie May 18 '17 at 10:35

You don't understand what you are doing. All PHP code (and also the backtick/exec/system commands) is executed on the server.

There is no portable/reliable way to get the MAC address. Maybe a browser plugin could do that.

Consider that the client can also not have any MAC addresses at all. For example when connecting via PPP.

Not the answer you're looking for? Browse other questions tagged or ask your own question.