0

I was wondering if there is a way to use PHP or JavaScript to get the mac address of a computer, to use as a multi-part User Authentication. Or can it only be done in Java??

if in Java how would I write the output to a php Variable??

Thanks in advance

  • Just a side note, a MAC address can be altered or "spoofed". Be careful using this as authentication, multi-part should be fine, though. – Brandon White Jul 23 '14 at 16:29
  • 2
    if you can read mac address with JavaScript it will be a security breach. – bansi Jul 23 '14 at 16:31
  • Looks like is described here: http://stackoverflow.com/questions/3385/mac-addresses-in-javascript – lpg Jul 23 '14 at 16:33
  • The admin page would be for a website (my company's) and the only person accessing it would be me, but passwords are crack-able, and yes MAC addresses are "spoof-able", i was also going to add a security code (via text message), so I am not too concerned about the alteration of a MAC address. –  Jul 23 '14 at 16:34

1 Answers1

1

The client MAC address will not be available to you except in one special circumstance: if the client is on the same ethernet segment as the server.

So, if you are building some kind of LAN based system and your clients are on the same ethernet segment, then you could get the MAC address by parsing the output of arp -n (linux) or arp -a (windows).

Igor Pejic
  • 3,658
  • 1
  • 14
  • 32
  • Is there a way to get the MAC address through Java, then save it to a php variable?? –  Jul 23 '14 at 16:37
  • IMPLEMENTATION WITH PHP ONLY: $ipAddress=$_SERVER['REMOTE_ADDR']; $macAddr=false; #run the external command, break output into lines $arp=`arp -a $ipAddress`; $lines=explode("\n", $arp); #look for the output line describing our IP address foreach($lines as $line) { $cols=preg_split('/\s+/', trim($line)); if ($cols[0]==$ipAddress) { $macAddr=$cols[1]; } } – Igor Pejic Jul 23 '14 at 16:39
  • 1
    I thought of this when i saw your answer, if one is capable of running cmd commands from php then the command getmac (windows command), ifconfig -a(linux command) should work as well. the php command to return just the mac address on windows is `echo substr(exec("getmac"), 0, 17);` –  Jul 23 '14 at 16:59