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

WBOY
풀어 주다: 2016-07-25 09:09:52
원래의
908명이 탐색했습니다.
  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. ?>
复制代码


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!