PHP: getting MAC address-specific instance _ PHP Tutorial

Source: Internet
Author: User
PHP obtains the specific instance of the MAC address. This section describes the php code. The main function is to obtain the physical (MAC) address of the machine Nic. Code: Copy the code as follows :? Php *** obtain the physical (MAC) address of the machine Nic * The php code currently shared in this section. main functions:
Obtain the physical (MAC) address of the machine Nic.
Code:

The code is as follows:


/**
* Obtain the physical (MAC) address of the machine Nic
* Currently, Windows/LINUX systems are supported.
**/
Class MacAddInfo {
Var $ return_array = array (); // returns a string array with a MAC address.
Var $ mac_addr;

Function MacAddInfo ($ OS _type ){
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-> return_array 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-> mac_addr = $ temp_array [0];
Break;
}
}
Unset ($ temp_array );
Return $ this-> mac_addr;
}

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

Function forLinux (){
@ Exec ("ifconfig-a", $ this-> return_array );
Return $ this-> return_array;
}
}
// Call example
// $ Mac = new MacAddInfo (PHP_ OS );
// Echo $ mac-> mac_addr;
?>

Obtain the physical (MAC) address of the machine Nic. Code: The code is as follows :? Php/*** obtain the physical (MAC) address of the machine Nic * currently...

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.