Retrieve local MAC address via PHP
Ever wanted to give out a script that should be restricted to run on one PC? Well, of course you can buy the expensive ioncube pro version which has this feature build in, but the cheaper one ( 199 $ ) also does the job, if you write your own function - which is actually mentioned for windows based systems only.
It’s really not hard, and you can restrict any script to a certain MAC network adapter address. Here’s how to do it:
function getMac(){
exec("ipconfig /all", $output);
foreach($output as $line){
if (preg_match("/(.*)Physical Address(.*)/", $line)){
$mac = $line;
$mac = str_replace("Physical Address. . . . . . . . . :","",$mac);
}
}
return $mac;
}
$mac = getMac();
$mac = trim($mac);
After that, you only need to know the MAC address of the PC the script should run on, and compare that string to the one retrieved. To make the script really secure, you will have to obfuscate it, which can be done by any free PHP encoder or the splendid tool from ioncube.


May 23rd, 2008 at 4:23 pm
Dear sir
i just like to say,,, Thaaaaaaaaaaaaaaaank you…
i passed a huge time and effort while searching on this issue,,,,
thank you very very much
and i hope that you have no problem if i ask you for any help in the future
November 19th, 2008 at 1:45 pm
Hey! Thanks for your idea!
You mentioned this script is “windows based”, does that mean that is work only on windows? Does it work on other OSs, like Linux or Mac?
Thanks in advice!
January 8th, 2009 at 4:59 am
This is a good post, i’m searching around.
I think using MAC address could prevent unauthorized to access your system admin.
May 10th, 2009 at 3:45 am
It’s also handy to check the machine ID. This is even more fool proof than the MAC which can be cloned.
- Shelon Padmore