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.

4 Responses to “Retrieve local MAC address via PHP”

  1. saeed othman Says:

    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

    You#re welcome Saeed. And no - no problem at all, if you have questions, simply drop in a line :)

  2. moka Says:

    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!

  3. ergonomic-backpack Says:

    This is a good post, i’m searching around.
    I think using MAC address could prevent unauthorized to access your system admin.

  4. Shelon Padmore Says:

    It’s also handy to check the machine ID. This is even more fool proof than the MAC which can be cloned.

    - Shelon Padmore

 

Leave a Reply