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;
}
@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