Function code for PHP to obtain the MAC address. Copy the code as follows :? Php ** obtains the original MAC address of the NIC. Currently, the physical (MAC) address of the NIC can be obtained in WINLINUX ** classGetMacAddr {var $ return_array
The code is as follows:
/**
Obtain the MAC address source code of the NIC. Currently, Windows/LINUX systems are supported.
Obtain the physical (MAC) address of the machine Nic
**/
Class GetMacAddr {
Var $ return_array = array (); // returns a string array with a MAC address.
Var $ mac_addr;
Function GetMacAddr ($ 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;
}
}
// Method usage
// $ Mac = new GetMacAddr (PHP_ OS );
// Echo $ mac-> mac_addr;
?>
The http://www.bkjia.com/PHPjc/324255.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324255.htmlTechArticle code is as follows :? Php/** obtain the original MAC address of the NIC. Currently, Windows/LINUX supports obtaining the physical (MAC) address of the NIC. **/class GetMacAddr {var $ return_array...