Php obtains the mac address of the server and client to obtain the mac address of the server & lt ;? Php ** obtains the original MAC address of the NIC. Currently, the physical (MAC) address of the NIC can be obtained in WINLINUX ** classGetmacAddr {var $ resultarray (); returns the string array var $ macAddr with the MAC address. php obtains the mac address of the server and the mac address of the client.
Get server mac
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 system */Function for_linux_ OS () {@ exec ("ifconfig-a", $ this-> result); return $ this-> result ;} /* obtain method in win system */function for_windows_ OS () {@ exec ("ipconfig/all", $ this-> result); if ($ this-> result) {return $ this-> result;} else {$ ipconfig = $ _ SERVER ["WINDIR"]. "\ system32 \ ipconfig.exe"; if (is_file ($ ipconfig) {@ exec ($ ipconfig. "/all", $ this-> result);} else {@ exec ($ _ SERVER ["WINDIR"]. "\ system \ ipco Nfig.exe/all ", $ this-> result); return $ this-> result ;}}}?>
Obtain the client mac address:
@ Exec ("arp-a", $ array); // execute the arp-a command and put the result into the array $ array foreach ($ array as $ value) {// put the matching result in an array $ 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;
Note: The mac obtained by the client cannot be tested on the local machine. only access from other computers can be used for output.