标签:
PHP获取服务器的mac地址类,不是客户端的。
1 <?php 2 3 class GetMacAddr{ 4 5 var $return_array = array(); // 返回带有MAC地址的字串数组 6 var $mac_addr; 7 8 function GetMacAddr($os_type){ 9 switch ( strtolower($os_type) ){ 10 case "linux": 11 $this->forLinux(); 12 break; 13 case "solaris": 14 break; 15 case "unix": 16 break; 17 case "aix": 18 break; 19 default: 20 $this->forWindows(); 21 break; 22 } 23 24 25 $temp_array = array(); 26 27 foreach ( $this->return_array as $value ){ 28 if (preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i",$value, $temp_array ) ){ 29 $this->mac_addr = $temp_array[0]; 30 break; 31 } 32 33 } 34 unset($temp_array); 35 return $this->mac_addr; 36 } 37 38 39 function forWindows(){ 40 @exec("ipconfig /all", $this->return_array); 41 if ( $this->return_array ) 42 return $this->return_array; 43 else{ 44 $ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe"; 45 46 if ( is_file($ipconfig) ) 47 @exec($ipconfig." /all", $this->return_array); 48 else 49 @exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->return_array); 50 51 52 return $this->return_array; 53 } 54 } 55 56 57 58 function forLinux(){ 59 @exec("ifconfig -a", $this->return_array); 60 return $this->return_array; 61 } 62 63 } 64 ?>
使用方法
include ‘Getmac.php‘; $mac = new GetMacAddr(PHP_OS); echo $mac->mac_addr;
标签:
原文地址:http://www.cnblogs.com/manongxiaobing/p/4378754.html