• 技术文章 >php教程 >PHP源码

    PHP读取网卡MAC地址

    PHP中文网PHP中文网2016-05-23 16:38:52原创568
    PHP读取网卡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中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    上一篇:使用etag和文件缓存降低服务器数据库压力 下一篇:php cms门户网站模版
    大前端线上培训班

    相关文章推荐

    • Yaf框架入门只hello yaf• php生成略缩图程序代码与详细介绍• 图片加水印程序 • 5种方法让你成为php开发高手• 简单数据库操作的Model类

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网