-1

I want to get a mac address from a client's computer which are using my web application.

I did exec('netstat -ie'); but I can't get anything and I want to know the right way.

Funk Forty Niner
  • 73,764
  • 15
  • 63
  • 131
Omprakash Patel
  • 498
  • 4
  • 14
  • 1
    PHP is running on the server side, not the clients machine. Therefore you are not able to get the mac address of a machine that's on your site. I think javascript isn't able to do this either. – Arthur May 30 '17 at 12:27
  • `exec()` will fire on the host your website is hosted on! – Daan May 30 '17 at 12:27
  • 2
    This was already asked by the way: https://stackoverflow.com/questions/1420381/how-can-i-get-the-mac-and-the-ip-address-of-a-connected-client-in-php – Arthur May 30 '17 at 12:29

2 Answers2

3

Try using the following:

$ipAddress=$_SERVER['REMOTE_ADDR'];
$arp=`arp -a $ipAddress`;
$output = shell_exec($arp);

Keep in mind this only works with clients on the same ethernet segment

sietse85
  • 1,335
  • 1
  • 7
  • 22
0
$ipAddress=$_SERVER['REMOTE_ADDR'];
$macAddr=false;

#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)
   {
       $macAddr=$cols[1];
   }
}
kevin
  • 224
  • 1
  • 12
  • you need to execute the arp command first with `shell_exec()` before you receive output, so this won't work – sietse85 May 30 '17 at 14:51