PHP获取MAC地址的函数代码

yipeiwu_com6年前PHP代码库

复制代码 代码如下:

<?php
/**
获取网卡的MAC地址原码;目前支持WIN/LINUX系统
获取机器网卡的物理(MAC)地址
**/
class GetMacAddr{
var $return_array = array(); // 返回带有MAC地址的字串数组
var $mac_addr;
function GetMacAddr($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"]."\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;
?>

相关文章

php与paypal整合方法

我晕,最近这个用paypal付款的功能搞了我2天,还没搞完。郁闷死了。 先做个笔记,把已经搞定的部分写下来,省的以后忘了。 1 注册SandBox账号,并且建立两个虚拟账号,可以选择自动...

php中注册器模式类用法实例分析

本文实例讲述了php中注册器模式类用法。分享给大家供大家参考,具体如下: 注册器读写类 Registry.class.php <?php /** * 注册器读写类...

php中的动态调用实例分析

本文实例讲述了php中的动态调用具体用法。分享给大家供大家参考。具体分析如下: 在程序中如果加一大堆判断的确是一个很大的麻烦,例如这样: 复制代码 代码如下:if($fun='a'){e...

详解PHP错误日志的获取方法

在PHP中错误日志的获取方法有很多种,下面我给大家简单介绍下遇到此类问题如何解决,下面通过代码给大家展示下,希望能够帮助到大家。 <?php error_reporti...

简单了解PHP编程中数组的指针的使用

要使用数组中的元素,就需要数组的定位。定位的实现需要借助数组指针来完成。PHP中有很多函数可以移动数组指针。下面将给大家介绍几个。 将指针移动到下一个数组位置next() next()函...