Skip to content

Instantly share code, notes, and snippets.

@zhenyi2697
Created August 2, 2013 08:17
Show Gist options
  • Select an option

  • Save zhenyi2697/6138283 to your computer and use it in GitHub Desktop.

Select an option

Save zhenyi2697/6138283 to your computer and use it in GitHub Desktop.
PHP: get mac address from php
<?php
function getMacLinux() {
exec('netstat -ie', $result);
if(is_array($result)) {
$iface = array();
foreach($result as $key => $line) {
if($key > 0) {
$tmp = str_replace(" ", "", substr($line, 0, 10));
if($tmp <> "") {
$macpos = strpos($line, "HWaddr");
if($macpos !== false) {
$iface[] = array('iface' => $tmp, 'mac' => strtolower(substr($line, $macpos+7, 17)));
}
}
}
}
return $iface[0]['mac'];
} else {
return "notfound";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment