Php obtains the mac address of the client Nic
|
In php programming, the user's mac address can be obtained to bind to the customer's computer and prevent junk registration.
A very simple class. you only need to print its macAddr attribute After instantiation.
Code:
- Class Getmac {
- Var $ result = array (); // returns a string array with a MAC address
- Var $ macAddr;
- /* Construct */
- Function _ construct ($ osType ){
- Switch (strtolower ($ osType )){
- Case "unix": break;
- Case "solaris": break;
- Case "aix": break;
- Case "linux ":{
- $ This-> 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;
- }
- /* Obtain methods in linux */
- Function for_linux_ OS (){
- @ Exec ("ifconfig-a", $ this-> result );
- Return $ this-> result;
- }
- /* Obtain methods 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 \ ipconfig.exe/all", $ this-> result );
- Return $ this-> result;
- }
- }
- }
- }
- /* 1. implementation class 2. access its macAddr attribute directly */
- $ GetMac = new Getmac (PHP_ OS );
- Echo $ getMac-> macAddr;
- ?>
|
Client, Nic