wangduowu 发表于 2013-1-15 02:55:17

PHP 读取MAC地址

代码:
<?phpclass GetMacAddress {var $return_array = array();var $mac_addr;function _construct($os_type) {switch (strtolower($os_type)) {case   "linux":$this->forLinux();break;default:$this->forWindows();break;}$temp_array = array();foreach ($this->return_array as $value) {if (preg_match("/[:-]"."[:-]"."[:-]"               ."[:-]"."[:-]"."/i", $value, $temp_array)) {$this->mac_addr = $temp_array;break;}}unset($temp_array);return $this->mac_addr;}function forWindows() {@exec("ipconfig /all", $this->return_array);if ($this->return_array) {return $this->return_array;} else {$ipconfig = $_SERVER["SystemRoot"]."\system32\ipconfig.exe";if (is_file($ipconfig)) {@exec($ipconfig." /all", $this->return_array);} else {@exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->return_array);}return $this->return_array;}}function forLinux() {@exec("ifconfig-a", $this->return_array);return $this->return_array;}}$mac = new GetMacAddress(null);echo $mac->mac_addr;?> 
 
 
 
页: [1]
查看完整版本: PHP 读取MAC地址