php获取电脑网卡物理(MAC)地址的方法
<?php class MacAddInfo { var $return_array = array (); 返回带有MAC地址的字串数组 var $mac_addr; functi
天晟网小编整理编程教程 > PHP > 时看到php获取电脑网卡物理(MAC)地址的方法 ,下面有小编45为你找到的37975相关内容希望对你45有所帮助。
<?phpclass MacAddInfo {
var $return_array = array (); // 返回带有MAC地址的字串数组
var $mac_addr;
function MacAddInfo($os_type) {
switch (strtolower ( $os_type )) {
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];
break;
}
}
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"] . "system32ipconfig.exe";
if (is_file ( $ipconfig ))
@exec ( $ipconfig . " /all", $this->return_array );
else
@exec ( $_SERVER ["WINDIR"] . "systemipconfig.exe /all", $this->return_array );
return $this->return_array;
}
}
function forLinux() {
@exec ( "ifconfig -a", $this->return_array );
return $this->return_array;
}
}
//调用
$mac = new MacAddInfo(PHP_OS);
echo $mac->mac_addr;
?>
文章转载请注明来自天晟网 > 编程教程 > PHP >
原文标题:php获取电脑网卡物理(MAC)地址的方法
原文网址:http://www.timsion.com/php/37975.html
上一篇:php将当前网页创建为桌面快捷方式的方法
下一篇:php判断gif图片是否为动画图片的方法
免责声明:以上内容来自互联网和用户投稿,不代表本站的观点和立场,版权归原作者所有,如有侵权,请与我们联系。