在php编程中,获取到用户mac地址,就可以实现与客户电脑的绑定、防止垃圾注册等。
一个非常简单的类,使用时只要实例化后直接打印它的macaddr属性即可。
代码: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;
}
}
}
}
/*1.实现化类 2.直接访问它的macaddr属性*/
$getmac = new getmac(php_os);
echo $getmac->macaddr;
?>
复制代码
客户端, 网卡