Skip to content

Instantly share code, notes, and snippets.

@JunaidQadirB
Created August 17, 2011 15:50
Show Gist options
  • Save JunaidQadirB/1151838 to your computer and use it in GitHub Desktop.
Save JunaidQadirB/1151838 to your computer and use it in GitHub Desktop.
Getting MAC Address of the host using PHP
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;
}
@j0inty
Copy link

j0inty commented Jun 14, 2015

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

@cmusiq92
Copy link

cmusiq92 commented Oct 2, 2018

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