现在的位置: 网页制作教程网站制作教程 >正文
php网上学习

PHP如何获取服务器mac地址

发表于2017/5/22 网站制作教程 0条评论 ⁄ 热度 2,526℃

本文介绍PHP获取服务器mac地址的方法。获取代码如下:

<?php
/**
获取网卡的MAC地址原码;目前支持WIN/LINUX系统
获取机器网卡的物理(MAC)地址
**/
class GetmacAddr{
var $result = array(); // 返回带有MAC地址的字串数组
var $macAddr;
/*构造*/
function __construct($osType){
switch ( strtolower($osType) ){
case "unix": break;
case "solaris": break;
case "aix": break;
case "linux": {
$this->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;
}
}
}
}
?>
  • 暂无评论