How to Get the MAC and the Ip Address of a Connected Client in PHP

How to get MAC address of client using PHP?

You can get the client's MAC address in javascript, if they are running Windows and allow you to install an ActiveX control.

How to get client MAC address when visit to my website?

Normally it is not possible for security issue. Because MAC address is your machine address and your server can not able to access your machine. The MAC address is not broadcast beyond the LAN the device is connected to - it never leaves the router and passes to the server.

PHP: Get client MAC address

There is no way, the MAC is not included in the TCP/IP stack and once routed, the client MAC is not visible.
MAC = Layer 2

-- edit:

But if it is your app protocol, you can build it in yourself. Put the client MAC into your communication.

Get MAC address from client's machine

Ah, the old exec() vs shell_exec() vs passthru() question.

To see what command is actually being run, and what the system is actually returning, use exec(), and pass it an int and an array as its 2nd and 3rd params respectively, then var_dump() them both after running the command.

For example:

$cmd = "arp -a " . $ip;
$status = 0;
$return = [];
exec($cmd, $return, $status);
var_dump($status, $return);

If everything went OK, then $status should be zero and $return may or may not be empty. However if $status is non-zero then pay attention to what the value of $return is, as this will be what your system is telling you is happening when it tries to run your command.

Protip: Pass exec() the full path to arp as-in:

#> which arp

$cmd = "/usr/sbin/arp -a" . $ip;

Also, bear in mind, depending on where the command is being run, REMOTE_ADDR may not return anything useful. There are several other ways of obtaining an IP address, which are especially useful if the IP address you need is behind some sort of proxy.

Related Topics

Leave a reply