Search code examples
macosmac-address

Get MAC address


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

From ethernet user.

Thanks.


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.