zoukankan      html  css  js  c++  java
  • php获取server端mac和clientmac的地址

    获取servermac

    <?php   
    /**  
    获取网卡的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; 
                }
            } 
        } 
    } 
    ?

    >


    获取clientmac地址:

    @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;
    注:client获取的mac不能在本机測试,仅仅能用别的电脑訪问才干输出

  • 相关阅读:
    BZOJ4237:稻草人
    BZOJ4009:[HNOI2015]接水果(整体二分版)
    BZOJ3745:[COCI2015]Norma
    BZOJ3110:[ZJOI2013]K大数查询(整体二分版)
    BZOJ2716:[Violet 3]天使玩偶
    BZOJ2527:[POI2011]Meteors
    BZOJ4170:极光
    BZOJ1901:Dynamic Rankings
    Python基础终极实战 基于C/S架构的仿优酷项目
    大白话五种IO模型
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5123622.html
Copyright © 2011-2022 走看看