Php obtains the mac address of the server and client.

Source: Internet
Author: User
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.

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.