时时商务社区
标题:
php获取网卡的MAC地址支持WIN/LINUX系统
[打印本页]
作者:
yj1281
时间:
2018-2-14 05:58
[U]复制代码[/U] 代码如下:
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"]."\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(PHP_OS);
echo $mac->mac_addr; //这里是机器的真实MAC地址,请注释掉
?>
您可能感兴趣的文章:
Linux系统下双网卡配置实践总结
linux 双网卡绑定网络设置方法
linux系统单网卡绑定双IP的具体操作方法
自动生成linux网卡配置脚本分享
Linux服务器网卡流量查看方法 shell和Python各一枚
ubuntu (linux)修改网卡名称命令
Linux学习之CentOS(二十九)--Linux网卡高级命令、IP别名及多网卡绑定的方法
详解Linux查看实时网卡流量的几种方式
linux 网卡配置详解及实例
Linux系统网卡设置教程
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2