zoukankan      html  css  js  c++  java
  • PHP获取服务器的mac地址类

    PHP获取服务器的mac地址类,不是客户端的。

     1 <?php 
     2 
     3 class GetMacAddr{  
     4     
     5         var $return_array = array(); // 返回带有MAC地址的字串数组  
     6         var $mac_addr;  
     7 
     8         function GetMacAddr($os_type){  
     9                 switch ( strtolower($os_type) ){  
    10                         case "linux":  
    11                                 $this->forLinux();  
    12                                 break;  
    13                         case "solaris":  
    14                                 break;  
    15                         case "unix":  
    16                                  break;  
    17                         case "aix":  
    18                                  break;  
    19                         default:  
    20                                  $this->forWindows();  
    21                                  break;
    22                 }  
    23 
    24 
    25                 $temp_array = array();
    26 
    27                 foreach ( $this->return_array as $value ){
    28                         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 ) ){  
    29                                 $this->mac_addr = $temp_array[0];  
    30                                 break;  
    31                         }  
    32 
    33                 }
    34                 unset($temp_array);  
    35                 return $this->mac_addr;  
    36         }  
    37 
    38 
    39         function forWindows(){  
    40                 @exec("ipconfig /all", $this->return_array);  
    41                 if ( $this->return_array )  
    42                        return $this->return_array;  
    43                 else{  
    44                        $ipconfig = $_SERVER["WINDIR"]."system32ipconfig.exe"; 
    45                                 
    46                        if ( is_file($ipconfig) )  
    47                           @exec($ipconfig." /all", $this->return_array);                          
    48                        else  
    49                           @exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->return_array);
    50                                   
    51                              
    52                        return $this->return_array;  
    53                 }  
    54         }  
    55 
    56 
    57 
    58         function forLinux(){  
    59                 @exec("ifconfig -a", $this->return_array);  
    60                 return $this->return_array;  
    61         }
    62      
    63 }   
    64 ?>

    使用方法

    include 'Getmac.php'; 
    $mac = new GetMacAddr(PHP_OS);
    echo $mac->mac_addr;
  • 相关阅读:
    request常用的方法
    JS通过正则限制 input 输入框只能输入整数、小数(金额或者现金)
    基于云原生的秒杀系统设计思路
    html<input>输入框中各种正则表达式设置
    cursor:hand与cursor:pointer的区别介绍
    读入/输出优化
    手动扩栈,防止溢出
    快速乘(O(1))
    二分图若干性质
    康拓展开
  • 原文地址:https://www.cnblogs.com/manongxiaobing/p/4378754.html
Copyright © 2011-2022 走看看