...

View Full Version : Get MAC adress using PHP



phpdeveloper
02-18-2012, 01:48 PM
I want to get MAC address with php script.
Is it possible to get MAC address directly using PHP script?

If any one have idea about MAC address please help to to get.

Thanks in advance

tangoforce
02-18-2012, 02:02 PM
AFAIK No it can't be done in PHP. The server is on a totally different subnet and has no access to your subnet to scan it for mac addresses etc.

Inigoesdr
02-18-2012, 02:30 PM
Are you referring to the MAC address of the server or the client?

qeemat
02-20-2012, 11:19 AM
// Get the arp executable path
$location = `which arp`;
// Execute the arp command and store the output in $arpTable
$arpTable = `$location`;
// Split the output so every line is an entry of the $arpSplitted array
$arpSplitted = split("\n",$arpTable);
// Get the remote ip address (the ip address of the client, the browser)
$remoteIp = $GLOBALS['REMOTE_ADDR'];
// Cicle the array to find the match with the remote ip address
foreach ($arpSplitted as $value) {
// Split every arp line, this is done in case the format of the arp
// command output is a bit different than expected
$valueSplitted = split(" ",$value);
foreach ($valueSplitted as $spLine) {
if (preg_match("/$remoteIp/",$spLine)) {
$ipFound = true;
}
// The ip address has been found, now rescan all the string
// to get the mac address
if ($ipFound) {
// Rescan all the string, in case the mac address, in the string
// returned by arp, comes before the ip address
// (you know, Murphy's laws)
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;
}

tangoforce
02-20-2012, 11:36 AM
// Get the arp executable path
$location = `which arp`;
// Execute the arp command and store the output in $arpTable
$arpTable = `$location`;

Having just run those two lines of code, I got these results from var_dump() for both those variables:
NULL
NULL

The comment mentions executing the arm command yet you show no way of doing so. Are you using exec, system or what?

At the moment your code doesn't really do much to help anyone. IF you're going to sign up to post that then I think the least you could do is make sure its ready to use.

KuriosJon
02-20-2012, 12:41 PM
No matter what programming language you use, it's impossible to get the MAC address of any machine outside of your network; it's simply not available.

If this PHP code is being accessed locally, then you can use PHP to execute certain windows/linux commands to get the MAC. If this is the case, let us know.

Inigoesdr
02-20-2012, 02:07 PM
The comment mentions executing the arm command yet you show no way of doing so. Are you using exec, system or what?

shell_exec() (http://php.net/language.operators.execution)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum