How to get MAC address of client using PHP?

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

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

10条回答
  •  眼角桃花
    2020-11-28 08:58

    First you check your user agent OS Linux or windows or another. Then Your OS Windows Then this code use:

    public function win_os(){ 
        ob_start();
        system('ipconfig-a');
        $mycom=ob_get_contents(); // Capture the output into a variable
        ob_clean(); // Clean (erase) the output buffer
        $findme = "Physical";
        $pmac = strpos($mycom, $findme); // Find the position of Physical text
        $mac=substr($mycom,($pmac+36),17); // Get Physical Address
    
        return $mac;
       }
    

    And your OS Linux Ubuntu or Linux then this code use:

    public function unix_os(){
        ob_start();
        system('ifconfig -a');
        $mycom = ob_get_contents(); // Capture the output into a variable
        ob_clean(); // Clean (erase) the output buffer
        $findme = "Physical";
        //Find the position of Physical text 
        $pmac = strpos($mycom, $findme); 
        $mac = substr($mycom, ($pmac + 37), 18);
    
        return $mac;
        }
    

    This code may be work OS X.

提交回复
热议问题