Php/js implementation code for obtaining client mac address _ php instance

Source: Internet
Author: User
This article mainly introduces how to obtain the customer's mac address in php and js respectively. If you need a friend, you can refer to this article for more information and directly go to the code!

The Code is as follows:


Class MacAddr
{
Public $ returnArray = array ();
Public $ macAddr;

Function _ contruct ($ OS _type = null ){
If (is_null ($ OS _type) $ OS _type = PHP_ OS;
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-> returnArray 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;
}

Function forWindows (){
@ Exec ("ipconfig/all", $ this-> returnArray );
If ($ this-> returnArray)
Return $ this-> returnArray;
Else {
$ Ipconfig = $ _ SERVER ["WINDIR"]. "system32ipconfig.exe ";
If (is_file ($ ipconfig ))
@ Exec ($ ipconfig. "/all", $ this-> returnArray );
Else
@ Exec ($ _ SERVER ["WINDIR"]. "systemipconfig.exe/all", $ this-> returnArray );
Return $ this-> returnArray;
}
}

Function forLinux (){
@ Exec ("ifconfig-a", $ this-> returnArray );
Return $ this-> returnArray;
}
}

$ Mac = new MacAddr (PHP_ OS );
Echo $ mac-> macAddr;
Echo"
";

// Obtain the client
// Linux
$ Command = "arp-a {$ _ SERVER ['remote _ ADDR ']}";
Echo $ command;
Echo"
";
$ Result = '{$ command }';

// Windows
$ Command = "nbtstat-a {$ _ SERVER ['remote _ ADDR ']}";
Echo $ command;
Echo"
";
$ Result = '{$ command }';
Print_r ($ result );
?>

There is no major problem in obtaining the server logic, and there may be permission issues.
When obtaining the client, it may be slow, and arp/nbstat command execution will be slow.

The Code is as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.