php读取mac地址
1. 2. 3. class GetMacAddress { 4. var $return_array = array(); 5. var $mac_addr; 6. 7. function _construct($os_type) { 8. switch (strtolower($os_type)) { 9. case "linux": 10. $this->forLinux(); 11. break; 12. default: 13. $this->forWindows(); 14. break; 15. } 16. 17. $temp_array = array(); 18. foreach ($this->return_array as $value) { 19. if (preg_match(”/[0-9a-f][0-9a-f][:-]“.”[0-9a-f][0-9a-f][:-]“.”[0-9a-f][0-9a-f][:-]” 20. .”[0-9a-f][0-9a-f][:-]“.”[0-9a-f][0-9a-f][:-]“.”[0-9a-f][0-9a-f]/i”, $value, $temp_array)) { 21. $this->mac_addr = $temp_array[0]; 22. break; 23. } 24. } 25. 26. unset($temp_array); 27. return $this->mac_addr; 28. } 29. 30. function forWindows() { 31. @exec(”ipconfig /all”, $this->return_array); 32. 33. if ($this->return_array) { 34. return $this->return_array; 35. } else { 36. $ipconfig = $_SERVER["SystemRoot"].”\system32\ipconfig.exe”; 37. if (is_file($ipconfig)) { 38. @exec($ipconfig.” /all”, $this->return_array); 39. } else { 40. @exec($_SERVER["WINDIR"].”\system\ipconfig.exe /all”, $this->return_array); 41. } 42. return $this->return_array; 43. } 44. } 45. 46. function forLinux() { 47. @exec(”ifconfig -a”, $this->return_array); 48. return $this->return_array; 49. } 50. } 51. 52. $mac = new GetMacAddress(null); 53. echo $mac->mac_addr; 54. 55. ?>