Rumah  >  Artikel  >  pembangunan bahagian belakang  >  获取机器网卡的物理(MAC)地址

获取机器网卡的物理(MAC)地址

WBOY
WBOYasal
2016-07-25 09:09:52909semak imbas
  1. /**
  2. 获取机器网卡的物理(MAC)地址
  3. **/
  4. class GetMacAddr
  5. {
  6. var $return_array = array(); // 返回带有MAC地址的字串数组
  7. var $mac_addr;
  8. function GetMacAddr($os_type)
  9. {
  10. switch ( strtolower($os_type) )
  11. {
  12. case "linux ":
  13. $this-> forLinux();
  14. break;
  15. case "solaris ":
  16. break;
  17. case "unix ":
  18. break;
  19. case "aix ":
  20. break;
  21. default:
  22. $this-> forWindows();
  23. break;
  24. }
  25. $temp_array = array();
  26. foreach ( $this-> return_array as $value )
  27. {
  28. 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 ) )
  29. {
  30. $this-> mac_addr = $temp_array[0];
  31. break;
  32. }
  33. }
  34. unset($temp_array);
  35. return $this-> mac_addr;
  36. }
  37. function forWindows()
  38. {
  39. @exec( "ipconfig /all ", $this-> return_array);
  40. if ( $this-> return_array )
  41. return $this-> return_array;
  42. else{
  43. $ipconfig = $_SERVER[ "WINDIR "]. "\system32\ipconfig.exe ";
  44. if ( is_file($ipconfig) )
  45. @exec($ipconfig. " /all ", $this-> return_array);
  46. else
  47. @exec($_SERVER[ "WINDIR "]. "\system\ipconfig.exe /all ", $this-> return_array);
  48. return $this-> return_array;
  49. }
  50. }
  51. function forLinux()
  52. {
  53. @exec( "ifconfig -a ", $this-> return_array);
  54. return $this-> return_array;
  55. }
  56. }
  57. ?>
  58. $mac = new GetMacAddr(PHP_OS);
  59. echo $mac-> mac_addr;
  60. ?>
复制代码


Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:表单验证 Artikel seterusnya:mysql以文件形式导入导出整个数据库