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: