Question

How do I know visitor's MAC address on linux hosting (nginx)?

From ethernet user.

Thanks.

Was it helpful?

Solution

You cannot get that through PHP.

Networks protocol are used in a stack. When doing HTTP communications, your web server uses the HTTP protocol, responsible for the high-level communications. This protocol is implemented on the top of the TCP protocol (which brings stream-like connections and port numbers), which in turn is implemented on the top of the IP protocol (v4 or v6, which bring IP addresses for identification), which in turn is implemented on the top of the Ethernet protocol.

The Ethernet protocol is the one you would need to work with. It has both the source MAC address and the destination MAC address. However, most unfortunately, there are a lot of problems with it.

First, the data it conveys is probably hard to access: I say "probably" because I never stumbled upon how to do it.

Second, much like you get your client's router address when they access your site, you get your client's router MAC address at the Ethernet level. Unless they don't traverse any router (which would only happen if your server was directly wired to your client machine without any router interfering, because there are a whole lot of routers out there that relay data to other parts of the Internet), there is no chance that the MAC address you'll receive will be your client's.

Third, Apache will never try to access that data. And since PHP is "sandboxed" into the network environment Apache gives it, there is no way you can wind back to the Ethernet protocol.

So accessing the MAC address of a visitor from a website, from PHP, is not possible.

EDIT Seems you've taken out the PHP part from your question. So obviously, the last point won't stand anymore.

OTHER TIPS

You can't get that with php it's not included in http

The more general question is this one. Since all PHP has to work with (I'm assuming this is PHP running on your webserver, here) is the HTTP request, you won't be able to get the MAC address. That requires something running on the visitor's side.

This may, or may not work. I know it will work on LAN clients, however for external clients it may be incorrect. I don't overly know my networking, but it's worth a shot right?

If you execute the arp -a command on either windows or linux, it will print out your arp records, which you can then parse for the mac.

Other than that, as far as I know, apache (and therefor php) doesn't just give out mac addresses in its env vars.

*Edited: Sorry, that won't work... The better utility is arping however that will just give you the mac of your router.

If you want to do this, clients will need to be directly connected to your server, with no router in between...

However if that is the case, then arping will work... I don't know of a better tool, but it seems a bit wasteful to do a ping (in root) for just a mac address.

The mac address is only visible on for the network provider if i'm correct (your internet host can see the mac address of your router for example), don't think you can get it with php.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top