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

php中文网
发布: 2016-07-25 09:09:52
原创
1137人浏览过
  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. ?>
复制代码


最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号