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.
Trackback URL: Trackback URL
10. Apr, 2008 


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
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!
This is a good post, i’m searching around.
I think using MAC address could prevent unauthorized to access your system admin.
It’s also handy to check the machine ID. This is even more fool proof than the MAC which can be cloned.
- Shelon Padmore
Thank you so very much!!!
Dear sir
i just like to say,,, Thank you very much …
thanks alot to give that queries. i passed a huge time and effort while searching on this issue,,,,
thank you very very much
i have another one query sir can u help me..
how i detect hardware and software information using php sir in windows OS ??
How i find the speed of the internet ?? in php
how i show the lan system in php
Perfect thanks a million.
many thanks for info
I think the script will return the mac address of the server not of the client, isn’t it?
and the server must run on windows os, right? that also mean it should not work on other os like linux!?
plz rectify me if I am wrong.
thanks for the code, its a nice hack
Yes you’re right. This hack returns the MAC address of the system it runs on, and this way to utilize it is thought for windows platforms.
For linux there might be another solution.
Yet, still relating to windows, you can find the remote mac address of a PC by using the arp -a command. It shows all mac addresses from remote machines you are currently connected to.
So getting the IP address of the remote system is easy, then use it to find out the mac adress.
thanks you sir…
it is a great help for me and i’ve been trying this for a very long time
thanks a ton
For those who have more than one card as results like 3G modems or virtual cards :
exec(“ipconfig /all”, $output);
foreach($output as $line){
if (preg_match(“/(.*)Adresse physique(.*)/”, $line)){
$tempmac = trim(str_replace(“Physical Address. . . . . . . . . :”,”",$line));
if (($tempmac “”) && ($tempmac “00-00-00-00-00-00-00-E0″))
$mac[] = $tempmac;
}
}
echo $mac[0];
Thaaaaaaaaaaaaaaaanks alot
Thankyou very much. After all the negative responses from many other forums I was beginning to believe that it was impossible.
<?php
/*
* Getting MAC Address using PHP
* Muhammad Hanif Mianjee (thehanif@msn.com)
*/
ob_start(); // Turn on output buffering
system("ipconfig /all"); //Execute external program to display output
$mycom=ob_get_contents(); // Capture the output into a variable
ob_clean(); // Clean (erase) the output buffer
$findme = "Physical";
$pmac = strpos($mycom, $findme); // Find the position of Physical text
$mac=substr($mycom,($pmac+36),17); // Get Physical Address
echo $mac;