<?php /** access to network card MAC address of the original code; Currently supported Windows/LINUX system get the machine card physical (MAC) address **/ class GetMacAddr { var $return_array=array();//returns an array of strings with the MAC address var $mac_addr; function GetMacAddr ($os_type) { switch ($os_type) { case "Linux" : $this -> ForLinux(); break; case "solaris" : break; case "Unix" : break; case "wins" : $this -> ForWindows(); break; default: echo"plz select os"; break; } $temp_array=array(); foreach ($this ->return_array as $value) { if ( preg_match("/[0-9 a - f] [0-9] a - f [-] ". "[0-9 a - f] [0-9] a - f [-]". "[0-9 a - f] [0-9] a - f [-]". "[0-9 a - f] [0-9] a - f [-]". "[0-9 a - f] [0-9] a - f [-]". "[0-9 a - f] [0-9] a - f/I", $value, $temp_array)) { $this ->Mac_addr=$temp_array [0]; break; }} unset ($temp_array); return $this ->Mac_addr; } function forWindows () { //echo "wisn"; @exec("ipconfig/all", $this ->return_array);// interchange to echo instead of @ then display //error. if ($this -> return_array) return $this ->Return_array; else { $ipconfig=$_SERVER["WINDIR"]."\system32\ipconfig.exe"; if (is_file ($ipconfig)) echo 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 using the $MAC=new GetMacAddr("wins"); print_r($MAC ->Mac_addr); ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)