取得機器網路卡的實體(MAC)位址

WBOY
發布: 2016-07-25 09:09:52
原創
907 人瀏覽過
  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 "]. "system32ipconfig.exe ";
  44. if ( is_file($ipconfig) )
  45. @exec($ipconfig. " /all ", $this-> return_array);
  46. else
  47. @exec($_SERVER[ "WINDIR "]. "systemipconfig.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學習者快速成長!