3

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

From ethernet user.

Thanks.

Matt
  • 22,721
  • 17
  • 71
  • 112
James
  • 42,081
  • 53
  • 136
  • 161
  • Now that you've changed the question away from PHP... Is the visitor on the same LAN as the host, for starters? – Dan J Nov 18 '10 at 23:10
  • Then, as per the [other question I referenced](http://stackoverflow.com/questions/3309122/get-mac-address-from-http-request), you're pretty much out of luck. For what purpose do you require the MAC address? Perhaps we can suggest an alternative solution. – Dan J Nov 18 '10 at 23:17
  • @djacobson need this to ban spammers – James Nov 18 '10 at 23:36
  • It's possible to "change" MAC addresses anyway, if you have the right tools (MAC spoofing... Fun times) so this wouldn't work 100%. That said it'd probably be a little better than IP ban because significantly fewer people know how to change their MAC. – Ricky Cook Nov 18 '10 at 23:54

5 Answers5

8

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.

zneak
  • 134,922
  • 42
  • 253
  • 328
3

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

Galen
  • 29,976
  • 9
  • 71
  • 89
3

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.

Community
  • 1
  • 1
Dan J
  • 16,319
  • 7
  • 50
  • 82
1

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.

Ricky Cook
  • 951
  • 8
  • 14
0

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.

Mark Baijens
  • 13,028
  • 11
  • 47
  • 73