时间:2021-07-01 10:21:17 帮助过:6人阅读
获取服务器mac
for_linux_os(); }break; default: { $this->for_windows_os(); }break; } $temp_array = array(); foreach($this->result as $value){ 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 ) ){ $this->macAddr = $temp_array[0]; break; } } unset($temp_array); return $this->macAddr; } /*linux系统中获取方法*/ function for_linux_os(){ @exec("ifconfig -a", $this->result); return $this->result; } /*win系统中的获取方法*/ function for_windows_os(){ @exec("ipconfig /all", $this->result); if ( $this->result ) { return $this->result; } else { $ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe"; if(is_file($ipconfig)) { @exec($ipconfig." /all", $this->result); } else { @exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->result); return $this->result; } } } } ?>
@exec("arp -a",$array); //执行arp -a命令,结果放到数组$array中 foreach($array as $value){ //匹配结果放到数组$mac_array if(strpos($value,$_SERVER["REMOTE_ADDR"]) && preg_match("/(:?[0-9A-F]{2}[:-]){5}[0-9A-F]{2}/i",$value,$mac_array)){ $mac = $mac_array[0]; break; } } echo $mac;注:客户端获取的mac不能在本机测试,只能用别的电脑访问才能输出