PHP获取MAC地址
来源:互联网 发布:查看mac激活时间 编辑:程序博客网 时间:2024/05/17 04:17
http://www.cnblogs.com/nackman/archive/2012/07/22/2603443.html
/**
获取网卡的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"]."system32ipconfig.exe";
if(is_file($ipconfig)) {
@exec($ipconfig." /all", $this->result);
} else {
@exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->result);
return $this->result;
}
}
}
}
//获得服务器端的mac地址
$mac1 = new GetMacAddr(PHP_OS);
echo $mac1->macAddr;
echo "<br/>";
//获得客户端的mac地址
@exec("arp -a",$array); //执行arp -a命令,结果放到数组$array中
foreach($array as $value){
//匹配结果放到数组$mac_array
if(strpos($value,$_SERVER["REMOTE_ADDR"]) && preg_match("/(:?[0-9A-F]{2}[:-]){5}[0-9A-F]{2}/i",$value,$mac_array)){
$mac = $mac_array[0];
break;
}
}
echo $mac;
?>
获取网卡的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"]."system32ipconfig.exe";
if(is_file($ipconfig)) {
@exec($ipconfig." /all", $this->result);
} else {
@exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->result);
return $this->result;
}
}
}
}
//获得服务器端的mac地址
$mac1 = new GetMacAddr(PHP_OS);
echo $mac1->macAddr;
echo "<br/>";
//获得客户端的mac地址
@exec("arp -a",$array); //执行arp -a命令,结果放到数组$array中
foreach($array as $value){
//匹配结果放到数组$mac_array
if(strpos($value,$_SERVER["REMOTE_ADDR"]) && preg_match("/(:?[0-9A-F]{2}[:-]){5}[0-9A-F]{2}/i",$value,$mac_array)){
$mac = $mac_array[0];
break;
}
}
echo $mac;
?>
0 0
- PHP获取MAC地址
- PHP获取MAC地址
- PHP获取MAC地址
- php获取MAC地址
- php获取MAC地址
- PHP获取MAC地址
- PHP获取MAC地址
- PHP获取Mac地址
- PHP获取MAC地址
- php获取服务器MAC地址
- php 获取服务器端mac地址,客户端mac地址
- PHP获取网卡MAC地址的方法
- PHP获取网卡MAC地址的方法
- PHP获取网卡的MAC地址
- JS配合PHP获取客户端MAC地址
- 【引用】PHP获取本地MAC地址
- PHP 获取WindowOS下MAC地址
- PHP获取MAC地址的实现代码
- 获取手机的IMEI,MSISDN,ICCID,IMSI
- 某互联网金融公司“产品经理”培训圆满结束!
- C/C++中的void 和 void *
- Birt 报表参数的使用
- 数据结构之循环链表
- PHP获取MAC地址
- 南阳oj 语言入门 精挑细选 题目 263
- poj 3278 Catch That Cow
- C语言的魅力与瑕疵
- draw something in Java DEMO
- 高精度问题之大数求幂
- xcode 代码对齐插件-XAlign
- String.valueOf() toString() i+"" 效率
- js 倒计时