php 获取网卡mac
生活随笔
收集整理的這篇文章主要介紹了
php 获取网卡mac
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 <?php
2 /** PHP類
3 獲取機器網(wǎng)卡的物理(MAC)地址
4 Download by http://www.codefans.net
5 wwa $Exp
6 **/
7 class GetMacAddr
8 {
9 var $return_array = array(); // 返回帶有MAC地址的字串?dāng)?shù)組
10 var $mac_addr;
11
12 function GetMacAddr($os_type)
13 {
14 switch ( strtolower($os_type) )
15 {
16 case "linux":
17 $this->forLinux();
18 break;
19 case "solaris":
20 break;
21 case "unix":
22 break;
23 case "aix":
24 break;
25 default:
26 $this->forWindows();
27 break;
28 }
29
30 $temp_array = array();
31 foreach ( $this->return_array as $value )
32 {
33 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 ) )
34 {
35 $this->mac_addr = $temp_array[0];
36 break;
37 }
38 }
39 unset($temp_array);
40 return $this->mac_addr;
41 }
42
43 function forWindows()
44 {
45 @exec("ipconfig /all", $this->return_array);
46 if ( $this->return_array )
47 return $this->return_array;
48 else{
49 $ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";
50 if ( is_file($ipconfig) )
51 @exec($ipconfig." /all", $this->return_array);
52 else
53 @exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->return_array);
54 return $this->return_array;
55 }
56 }
57
58 function forLinux()
59 {
60 @exec("ifconfig -a", $this->return_array);
61 return $this->return_array;
62 }
63 }
64 ?>
?
轉(zhuǎn)載于:https://www.cnblogs.com/wenzhilin/p/3640516.html
總結(jié)
以上是生活随笔為你收集整理的php 获取网卡mac的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “CEPH浅析”系列之七——关于CEPH
- 下一篇: php method_exists 检测