PHP - MAC Address

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

PHP - MAC Address

Post 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?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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;
	}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this are shell commands though..
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

javascript has no access to MAC address information.
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Post 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...
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

feyd wrote:javascript has no access to MAC address information.
Twice.
Post Reply