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.

programming php ajax mysql Retrieve local MAC address via PHP admin

artViper designstudio is specialized in validating website design, programming in PHP and AJAX as well as mySQL. We're eager to design graphically impressive sites with convenient content and functions. As we want to share some of this knowledge, this blog has been created - may you find something of interest! Have fun.

I like it :)

 

Trackback URL: Trackback URL

 

15 Responses to “Retrieve local MAC address via PHP”

  1. 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. 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. This is a good post, i’m searching around.
    I think using MAC address could prevent unauthorized to access your system admin.

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

    - Shelon Padmore

  5. Thank you so very much!!!

  6. Akilanda Nageswari Reply 04. Jan, 2010 at 6:01 am

    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

  7. Perfect thanks a million.

  8. many thanks for info

  9. 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.

  10. prosenjit chowdhury Reply 17. Apr, 2011 at 9:12 pm

    thanks you sir…
    it is a great help for me and i’ve been trying this for a very long time

    thanks a ton

  11. 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];

  12. Thaaaaaaaaaaaaaaaanks alot

  13. Thankyou very much. After all the negative responses from many other forums I was beginning to believe that it was impossible.

  14. <?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;