How to get MAC address of client using PHP?

前端 未结 10 1618
长情又很酷
长情又很酷 2020-11-28 08:39

How can I get MAC Address using PHP or javascript...

相关标签:
10条回答
  • 2020-11-28 09:15

    To get client's device ip and mac address

    {
        if (isset($_SERVER['HTTP_CLIENT_IP']))
            $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
        else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
            $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
        else if(isset($_SERVER['HTTP_X_FORWARDED']))
            $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
        else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
            $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
        else if(isset($_SERVER['HTTP_FORWARDED']))
            $ipaddress = $_SERVER['HTTP_FORWARDED'];
        else if(isset($_SERVER['REMOTE_ADDR']))
            $ipaddress = $_SERVER['REMOTE_ADDR'];
        else
            $ipaddress = 'UNKNOWN';
    
        $macCommandString   =   "arp " . $ipaddress . " | awk 'BEGIN{ i=1; } { i++; if(i==3) print $3 }'";
    
        $mac = exec($macCommandString);
    
        return ['ip' => $ipaddress, 'mac' => $mac];
    }
    
    0 讨论(0)
  • 2020-11-28 09:15
    //Simple & effective way to get client mac address
    // Turn on output buffering
    ob_start();
    //Get the ipconfig details using system commond
    system('ipconfig /all');
    
    // Capture the output into a variable
    
        $mycom=ob_get_contents();
    
    // Clean (erase) the output buffer
    
        ob_clean();
    
    $findme = "Physical";
    //Search the "Physical" | Find the position of Physical text
    $pmac = strpos($mycom, $findme);
    
    // Get Physical Address
    $mac=substr($mycom,($pmac+36),17);
    //Display Mac Address
    echo $mac;
    
    0 讨论(0)
  • 2020-11-28 09:16

    You can get the client's MAC address in javascript, if they are running Windows and allow you to install an ActiveX control.

    http://www.eggheadcafe.com/community/aspnet/3/10054371/how-to-get-client-mac-address.aspx

    http://codingresource.blogspot.com/2010/02/get-client-mac-address-ip-address-using.html

    0 讨论(0)
  • 2020-11-28 09:18
    echo GetMAC();
    
    function GetMAC(){
        ob_start();
        system('getmac');
        $Content = ob_get_contents();
        ob_clean();
        return substr($Content, strpos($Content,'\\')-20, 17);
    }
    

    Above will basically execute the getmac program and parse its console-output, resulting to MAC-address of the server (and/or where ever PHP is installed and running on).

    0 讨论(0)
提交回复
热议问题