Created
August 17, 2011 15:50
-
-
Save JunaidQadirB/1151838 to your computer and use it in GitHub Desktop.
Getting MAC Address of the host using PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getMAC() | |
{ | |
/* | |
* Getting MAC Address of the host using PHP | |
* Md. Nazmul Basher | |
* Modified by Junaid Qadir Baloch | |
* Now this function gets all the MAC addresses attached to the system | |
* on which this function is called in an array and returns. | |
*/ | |
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 | |
foreach(preg_split("/(\r?\n)/", $mycom) as $line){ | |
if(strstr($line, 'Physical Address')) | |
{ | |
$Mac[]= substr($line,39,18); | |
} | |
} | |
return $Mac; | |
} |
This code will give us the server mac address not client mac
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I tested this function here on my windows system with german locale active and the script does not working anymore.
The problem is the translation for "Physical Address" what in german is "Physikalische Adresse".
I forked this repository and correct the function for all locale windows versions and tested it on an english and german installation. For that I recreated the preg_match pattern to an intl version.
Hope it helps
regards
j0inty