https://blog.csdn.net/iastro/article/details/78024005
https://www.programminghunter.com/article/2177344925/
mac地址是网卡地址一般情况下是无法获取到用户的mac地址地的,因为安全限制了浏览器所以几乎不太可能获取到了,下面拿两段代码给大家玩玩.
例1,PHP代码如下:";
print_r($array); //打印获取的数组
foreach($array as $value)
{
if( //匹配结果放到数组$mac_array
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
?>
例2,代码如下:forLinux();
break;
case "solaris":
break;
case "unix":
break;
case "aix":
break;
default:
$this->forWindows();
break;
}
$temp_array = 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];
break;
}
}
unset($temp_array);
return $this->macAddr;
}
function forWindows(){
@exec("ipconfig /all", $this->returnArray);
if($this->returnArray)
return $this->returnArray;
else{
$ipconfig = $_SERVER["WINDIR"]."system32ipconfig.exe";
if (is_file($ipconfig))
@exec($ipconfig." /all", $this->returnArray);
else
@exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->returnArray);
return $this->returnArray;
}
}
function forLinux(){
@exec("ifconfig -a", $this->returnArray);
return $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);
?>
获取服务端的逻辑没什么大问题,可能会存在权限问题,获取客户端的时候,可能会比较慢,arp/nbstat命令执行会比较慢,代码如下:
只适用于IE浏览器,而且会有告警提示.
永久链接:
转载随意!带上文章地址吧。