PHP获取Mac地址
2015-08-11 16:07
225 查看
<?php
class GetMacAddr
{
var $return_array = array(); // 返回带有MAC地址的字串数组
var $mac_addr=array();
function GetMacAddr()
{
switch (strtolower(PHP_OS) )
{
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];
}
}
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();
print_r( $mac->mac_addr);
?>
class GetMacAddr
{
var $return_array = array(); // 返回带有MAC地址的字串数组
var $mac_addr=array();
function GetMacAddr()
{
switch (strtolower(PHP_OS) )
{
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];
}
}
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();
print_r( $mac->mac_addr);
?>
相关文章推荐
- Phpcmsv9升级后验证码不显示的解决一 例
- 简单介绍PHP的责任链编程模式
- php性能分析工具 - xhprof的安装使用
- PHP ECSHOP中 诡异的问题:expects parameter 1 to be double
- php的curl扩展抓取信息——模拟登陆成功却无法抓取页面等问题
- thinkphp的配置文件
- Windows下配置PHP支持LDAP扩展方法(wampserver)
- Windows局域网通过NTP设置时间同步
- phpize简介
- swoole教程第一节:进程管理模块(Process)-中(消息队列)
- php,Yii获取当前url和域名和mysql查询语句
- 使用SeasLog打造PHP项目中的高性能日志组件(一)
- php和Mysql使用insert on duplicate分析
- 使用SeasLog打造PHP项目中的高性能日志组件(一)
- 7.PHP 教程_PHP常量
- PHP文件包含语句
- PHP之Traits
- Yii中CDbCriteria查询条件收集
- QwtPlot画曲线
- Zend_Json 简单介绍 --(手册)