Java世界

          學習筆記

          常用鏈接

          統計

          積分與排名

          天籟村

          新華網

          雅虎

          最新評論

          php獲取網卡的mac地址

          1. <?php ??
          2. /** ?
          3. 獲取網卡的MAC地址原碼;目前支持WIN/LINUX系統 ?
          4. 獲取機器網卡的物理(MAC)地址 ?
          5. **/ ??
          6. ??
          7. class ?GetMacAddr{ ??
          8. ??
          9. ??????? var ? $return_array ?=? array ();? //?返回帶有MAC地址的字串數組 ??
          10. ??????? var ? $mac_addr ; ??
          11. ??
          12. ??????? function ?GetMacAddr( $os_type ){ ??
          13. ???????????? switch ?(? strtolower ( $os_type )?){ ??
          14. ????????????????????? case ? "linux" : ??
          15. ??????????????????????????????? $this ->forLinux(); ??
          16. ??????????????????????????????? break ; ??
          17. ????????????????????? case ? "solaris" : ??
          18. ??????????????????????????????? break ; ??
          19. ????????????????????? case ? "unix" : ??
          20. ??????????????????????????????? break ; ??
          21. ????????????????????? case ? "aix" : ??
          22. ??????????????????????????????? break ; ??
          23. ????????????????????? default : ??
          24. ??????????????????????????????? $this ->forWindows(); ??
          25. ??????????????????????????????? break ; ??
          26. ??
          27. ????????????} ??
          28. ??
          29. ??????????? ??
          30. ???????????? $temp_array ?=? array (); ??
          31. ???????????? foreach ?(? $this ->return_array? as ? $value ?){ ??
          32. ??
          33. ?????????????????????? if ?( ??
          34. 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 , ??
          35. $temp_array ?)?){ ??
          36. ??????????????????????????????? $this ->mac_addr?=? $temp_array [0]; ??
          37. ??????????????????????????????? break ; ??
          38. ?????????????????????} ??
          39. ??
          40. ????????????} ??
          41. ????????????unset( $temp_array ); ??
          42. ???????????? return ? $this ->mac_addr; ??
          43. ???????} ??
          44. ??
          45. ??
          46. ??????? function ?forWindows(){ ??
          47. ????????????@ exec ( "ipconfig?/all" ,? $this ->return_array); ??
          48. ???????????? if ?(? $this ->return_array?) ??
          49. ????????????????????? return ? $this ->return_array; ??
          50. ???????????? else { ??
          51. ????????????????????? $ipconfig ?=? $_SERVER [ "WINDIR" ]. "\system32\ipconfig.exe" ; ??
          52. ????????????????????? if ?(? is_file ( $ipconfig )?) ??
          53. ????????????????????????@ exec ( $ipconfig . "?/all" ,? $this ->return_array); ??
          54. ????????????????????? else ??
          55. ????????????????????????@ exec ( $_SERVER [ "WINDIR" ]. "\system\ipconfig.exe?/all" ,? $this ->return_array); ??
          56. ????????????????????? return ? $this ->return_array; ??
          57. ????????????} ??
          58. ???????} ??
          59. ??
          60. ??
          61. ??
          62. ??????? function ?forLinux(){ ??
          63. ????????????@ exec ( "ifconfig?-a" ,? $this ->return_array); ??
          64. ???????????? return ? $this ->return_array; ??
          65. ???????} ??
          66. ??
          67. } ??
          68. //方法使用 ??
          69. //$mac?=?new?GetMacAddr(PHP_OS); ??
          70. //echo?$mac->mac_addr; ??
          71. ?>??

          posted on 2008-12-26 10:17 Rabbit 閱讀(686) 評論(1)  編輯  收藏

          評論

          # re: php獲取網卡的mac地址 2009-05-01 11:17 大盛大

          應該是先 用 ping 在用 arp來查吧

            回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 青州市| 扶余县| 云浮市| 廊坊市| 南和县| 巴塘县| 桐庐县| 荥阳市| 桃园县| 永和县| 建湖县| 罗田县| 赫章县| 宜川县| 香格里拉县| 天门市| 额敏县| 旬阳县| 益阳市| 余干县| 农安县| 图们市| 黑龙江省| 绥宁县| 会同县| 二连浩特市| 潢川县| 德惠市| 台江县| 稷山县| 南岸区| 吉木萨尔县| 梁山县| 罗甸县| 赣榆县| 虞城县| 陆川县| 富宁县| 富蕴县| 砚山县| 曲松县|