How to get the MAC address from Linux with PHP

This is how you can get the MAC address from Linux server with PHP when you need to find out the host for licence etc.

<?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";
  }
}

?>
Knowledge keywords: