MacAddr 类
{
公共 $returnArray = array();
公共$macAddr;
函数 __contruct($os_type=null){
if(is_null($os_type)) $os_type = PHP_OS;
开关 (strtolower($os_type)){
案例“linux”:
$this->forLinux();
休息;
案例“solaris”:
休息;
案例“unix”:
休息;
案例“aix”:
休息;
默认值:
$this->forWindows();
休息;
}
$temp_array = 数组();
foreach($this->returnArray 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];
休息;
}
}
取消设置($temp_array);
返回 $this->macAddr;
}
函数 forWindows(){
@exec("ipconfig /all", $this->returnArray);
if($this->returnArray)
返回 $this->returnArray;
其他{
$ipconfig = $_SERVER["WINDIR"]."system32ipconfig.exe";
if (is_file($ipconfig))
@exec($ipconfig." /all", $this->returnArray);
否则
@exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->returnArray);
返回 $this->returnArray;
}
}
函数 forLinux(){
@exec("ifconfig -a", $this->returnArray);
返回 $this->returnArray;
} }
$mac = new MacAddr(PHP_OS);
echo $mac->macAddr;
echo " ";
// 获取客户端
// linux
$command = "arp -a {$_SERVER['REMOTE_ADDR']}";
echo $command;
echo " ";
$result=`{$command}`;
// windows
$command = "nbtstat -a {$_SERVER['REMOTE_ADDR']}";
echo $command;
echo " ";
$result=`{$command}`;
print_r($result);
?>
|