Get mac address of client machine using php

In PHP, you can retrieve the MAC address of the client machine using the following steps:

Steps to get Mac address

  1. Use the $_SERVER['REMOTE_ADDR'] variable to get the IP address of the client machine.
  2. Use the exec() function to run the arp command on the server, passing the IP address as a parameter.
  3. Extract the MAC address from the output of the arp command.

Here's an example code snippet that demonstrates this process:

$mac = '';

// Execute the arp command and extract the MAC address
$arp_output = `arp -a $ip`;
$arp_lines = explode("\n", $arp_output);
foreach ($arp_lines as $line) {
    $cols = preg_split('/\s+/', trim($line));
    if ($cols[0] == $ip) {
        $mac = $cols[1];

echo "IP: $ip<br>";
echo "MAC: $mac";

Note that this method relies on the arp command being available on the server and having the necessary permissions to run it. Also, keep in mind that MAC addresses can be spoofed, so they should not be relied upon for security purposes.


Added  Mar 04, 12:59 pm

Article tags

SignUp with Email