Page 1 of 1

PHP - MAC Address

Posted: Thu Jul 15, 2004 8:00 am
by mikusan
Is it possible to retrieve the MAC address of a connection using JavaScript perhaps? I know there are many posts with IP blocking, but everyone knows the implications of that blocking system :wink: :wink:

I would like to retrieve it somehow, now, I don't know of anyway to poison the MAC adress if not using a proxy, but then I can block those modem kiddies. I cannot execute shell commands through php so that's out of the question.

Anyone ever done this? Am i totally on the wrong track?

Posted: Thu Jul 15, 2004 8:53 am
by kettle_drum
Should be able to use this if the server is linux/unix.

Code: Select all

function returnMacAddress() {
		$location = `which arp`;
		$arpTable = `$location`;
		$arpSplitted = split("\n",$arpTable);
		$remoteIp = $_SERVER['REMOTE_ADDR'];
		foreach ($arpSplitted as $value) {
			$valueSplitted = split(" ",$value);
			foreach ($valueSplitted as $spLine) {
				if (preg_match("/$remoteIp/",$spLine)) {
					$ipFound = true;
				}
	
				if ($ipFound) {
					reset($valueSplitted);
					foreach ($valueSplitted as $spLine) {
						if (preg_match("/[0-9a-f][0-9a-f][:-]".
							"[0-9a-f][0-9a-f][:-]".
							"[0-9a-f][0-9a-f][:-]".
							"[0-9a-f][0-9a-f][:-]".
							"[0-9a-f][0-9a-f][:-]".
							"[0-9a-f][0-9a-f]/i",$spLine)) {
							return $spLine;
						}
					}
				}
				$ipFound = false;
			}
		}
		return false;
	}

Posted: Thu Jul 15, 2004 10:55 am
by feyd
this are shell commands though..

Posted: Thu Jul 15, 2004 11:25 am
by kettle_drum
Yeah as you cant get the MAC address using php itself so you have to use arp to try and get the MAC address of the IP that connected.

Posted: Thu Jul 15, 2004 11:50 am
by mikusan
Hehe, yeah, I cannot execute PHP shell scripts, and I think most hosts should disallow it anyway, on a server we worked on, someone had a weak PHP script and they managed to get shell, then luckily our server crashed hehe, call it timing but it did that almost once a week, but that day it was early.

Anyways, I was thinking some JavaScript code, although I am not sure if it will be possible to beacon java variables back to PHP.

That was a pseudo question... 8O

Posted: Thu Jul 15, 2004 11:55 am
by feyd
javascript has no access to MAC address information.

Posted: Thu Jul 15, 2004 1:17 pm
by mikusan
Ah well I guess that's for the better... Javascript playing with ARP wow... that would be er.... not fun

Too bad i am not able to do this... I guess internet should be available to everyone... even the most annoying and uneducated people that make the most obnoxious of comments in forums everywhere...

Thanks for the help though...

Posted: Thu Jul 15, 2004 1:54 pm
by AVATAr
feyd wrote:javascript has no access to MAC address information.
Twice.