Rumah > php教程 > php手册 > PHP获取网卡MAC地址

PHP获取网卡MAC地址

WBOY
Lepaskan: 2016-06-21 08:53:32
asal
844 orang telah melayarinya
<ol class="dp-xml">
<li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span>    </span></span></li>
<li><span>/**    </span></li>
<li class="alt"><span>获取网卡的MAC地址原码;目前支持WIN/LINUX系统    </span></li>
<li><span>获取机器网卡的物理(MAC)地址    </span></li>
<li class="alt"><span>**/    </span></li>
<li><span>      </span></li>
<li class="alt"><span>class GetMacAddr{    </span></li>
<li><span>      </span></li>
<li class="alt">
<span>        var $</span><span class="attribute">return_array</span><span> = array(); // 返回带有MAC地址的字串数组    </span>
</li>
<li><span>        var $mac_addr;    </span></li>
<li class="alt"><span>      </span></li>
<li><span>        function GetMacAddr($os_type){    </span></li>
<li class="alt"><span>             switch ( strtolower($os_type) ){    </span></li>
<li><span>                      case "linux":    </span></li>
<li class="alt">
<span>                                $this-</span><span class="tag">></span><span>forLinux();    </span>
</li>
<li><span>                                break;    </span></li>
<li class="alt"><span>                      case "solaris":    </span></li>
<li><span>                                break;    </span></li>
<li class="alt"><span>                      case "unix":    </span></li>
<li><span>                                 break;    </span></li>
<li class="alt"><span>                       case "aix":    </span></li>
<li><span>                                 break;    </span></li>
<li class="alt"><span>                       default:    </span></li>
<li>
<span>                                 $this-</span><span class="tag">></span><span>forWindows();    </span>
</li>
<li class="alt"><span>                                 break;    </span></li>
<li><span>       </span></li>
<li class="alt"><span>              }    </span></li>
<li><span>       </span></li>
<li class="alt"><span>                  </span></li>
<li>
<span>              $</span><span class="attribute">temp_array</span><span> = array();    </span>
</li>
<li class="alt">
<span>              foreach ( $this-</span><span class="tag">></span><span>return_array as $value ){    </span>
</li>
<li><span>       </span></li>
<li class="alt"><span>                        if (    </span></li>
<li><span>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,    </span></li>
<li class="alt"><span>$temp_array ) ){    </span></li>
<li>
<span>                                 $this-</span><span class="tag">></span><span class="attribute">mac_addr</span><span> = $temp_array[0];    </span>
</li>
<li class="alt"><span>                                 break;    </span></li>
<li><span>                       }    </span></li>
<li class="alt"><span>       </span></li>
<li><span>              }    </span></li>
<li class="alt"><span>              unset($temp_array);    </span></li>
<li>
<span>              return $this-</span><span class="tag">></span><span>mac_addr;    </span>
</li>
<li class="alt"><span>         }    </span></li>
<li><span>       </span></li>
<li class="alt"><span>       </span></li>
<li><span>         function forWindows(){    </span></li>
<li class="alt">
<span>              @exec("ipconfig /all", $this-</span><span class="tag">></span><span>return_array);    </span>
</li>
<li>
<span>              if ( $this-</span><span class="tag">></span><span>return_array )    </span>
</li>
<li class="alt">
<span>                       return $this-</span><span class="tag">></span><span>return_array;    </span>
</li>
<li><span>              else{    </span></li>
<li class="alt">
<span>                       $</span><span class="attribute">ipconfig</span><span> = $_SERVER["WINDIR"]."\system32\ipconfig.exe";    </span>
</li>
<li><span>                       if ( is_file($ipconfig) )    </span></li>
<li class="alt">
<span>                          @exec($ipconfig." /all", $this-</span><span class="tag">></span><span>return_array);    </span>
</li>
<li><span>                       else    </span></li>
<li class="alt">
<span>                          @exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this-</span><span class="tag">></span><span>return_array);    </span>
</li>
<li>
<span>                       return $this-</span><span class="tag">></span><span>return_array;    </span>
</li>
<li class="alt"><span>              }    </span></li>
<li><span>         }    </span></li>
<li class="alt"><span>       </span></li>
<li><span>       </span></li>
<li class="alt"><span>       </span></li>
<li><span>         function forLinux(){    </span></li>
<li class="alt">
<span>              @exec("ifconfig -a", $this-</span><span class="tag">></span><span>return_array);    </span>
</li>
<li>
<span>              return $this-</span><span class="tag">></span><span>return_array;    </span>
</li>
<li class="alt"><span>         }    </span></li>
<li><span>       </span></li>
<li class="alt"><span>}    </span></li>
<li><span>//方法使用    </span></li>
<li class="alt">
<span>//$</span><span class="attribute">mac</span><span> = </span><span class="attribute-value">new</span><span> GetMacAddr(PHP_OS);    </span>
</li>
<li>
<span>//echo $mac-</span><span class="tag">></span><span>mac_addr;    </span>
</li>
<li class="alt">
<span class="tag">?></span><span>   </span>
</li>
</ol>
Salin selepas log masuk



Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan