How to get the MAC address from Linux with PHP?

MAC address from Linux with 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";
  }
}

?>

Found it on http://www.zimplicit.se/en/knowledge/how-get-mac-address-linux-php

One thought on “How to get the MAC address from Linux with PHP?

Leave a Reply

Your email address will not be published. Required fields are marked *

*