Created
August 2, 2013 08:17
-
-
Save zhenyi2697/6138283 to your computer and use it in GitHub Desktop.
PHP: get mac address from php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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