php代码获取客户端的MAC地址,供大家学习参考。
//取浏览器客户端的MAC地址
//by http://www.jbxue.com
class GetMacAddr
{
var $return_array = array(); // 返回带有MAC地址的字符串数组
var $mac_addr=array();
function GetMacAddr()
{
switch (strtolower(PHP_OS) )
{
case "linux":$this->forLinux();break;
case "solaris":break;
case "unix":break;
case "aix":break;
default:$this->forWindows();break;
}
$temp_array = array();
foreach ( $this->return_array 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->mac_addr[] = $temp_array[0];
}
}
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["WINDIR"]."\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 GetMacAddr();
echo "
";
print_r( $mac->mac_addr);
?>
2、获取客户端MAC(在同一个网关内有效)
function GetClientMac() {
$return_array = array();
$temp_array = array();
$mac_addr = "";
@exec("arp -a",$return_array);
foreach($return_array as $value) {
if(strPos($value,$_SERVER["REMOTE_ADDR"]) !== false && preg_match("/(:?[0-9a-f]{2}[:-]){5}[0-9a-f]{2}/i",$value,$temp_array)) {
$mac_addr = $temp_array[0];
break;
}
}
return ($mac_addr);
}
?>
您可能感兴趣的文章:
PHP获取MAC地址的实现代码
php获取电脑MAC地址的代码举例
php获取计算机唯一标识信息(cpu,网卡,MAC地址)
什么是MAC地址-基础知识
php获取网卡MAC地址与URL中主域