Click here to Skip to main content
15,886,648 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i get MAC Address of Client Using PHP
I have use
PHP
function getMacLinux() {
  exec('netstat -ie', $result);
   if(is_array($result)) {
    $iface = array();
    foreach($result as $key => $line) {
      if($key > 0) {
        $tmp = str_replace(" ", "", substr($line, 0, 10));
        if($tmp <> "") {
          $macpos = strpos($line, "HWaddr");
          if($macpos !== false) {
            $iface[] = array('iface' => $tmp, 'mac' => strtolower(substr($line, $macpos+7, 17)));
          }
        }
      }
    }
    return $iface[0]['mac'];
  } else {
    return "notfound";
  }
}



but it's giving server's MAC Address
is anyone know ???
Posted
Updated 16-Jan-22 4:22am
v2

Basically, you can't.
The MAC address is not broadcast beyond the LAN the device is connected to - it never leaves the router and passes to the server.

In theory you can get it in Javascript since that runs on the Client, but...and it's a big but...it's not going to work except in exceptional circumstances: you need to use an ActiveX control to get the MAC, and they only run under IE, and most systems default to "don't run ActiveX controls" to prevent all sorts of security problems.

If you want to use the MAC for identification, then don't bother - it won't do what you want most of teh time, and it is spectacularly simple to spoof. And there is also the fun that they aren't necessarily unique - just unique within the LAN segment...
 
Share this answer
 
Comments
priyankavm 14-May-15 6:56am    
Thanks a lot
OriginalGriff 14-May-15 7:05am    
You're welcome!
$mac = shell_exec("arp -a ".escapeshellarg($_SERVER['REMOTE_ADDR'])." | grep -o -E '(:xdigit:{1,2}:){5}:xdigit:{1,2}'");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900