Retrieve local MAC address via PHP

April 10, 2008 · Print This Article

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.

Comments

One Response to “Retrieve local MAC address via PHP”

  1. saeed othman on May 23rd, 2008 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

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

Got something to say?