PHP獲取MAC地址的具體實(shí)例
更新時(shí)間:2013年12月13日 16:25:58 作者:
分享一例php取得機(jī)器mac地址的代碼,學(xué)習(xí)下php讀取硬件信息的方法,此代碼適用于windows、linux系統(tǒng)。有需要的朋友參考學(xué)習(xí)下
本節(jié)分享的php代碼,主要功能:
獲取機(jī)器網(wǎng)卡的物理(MAC)地址。
代碼:
復(fù)制代碼 代碼如下:
<?php
/**
* 獲取機(jī)器網(wǎng)卡的物理(MAC)地址
* 目前支持WIN/LINUX系統(tǒng)
**/
class MacAddInfo {
var $return_array = array (); // 返回帶有MAC地址的字串?dāng)?shù)組
var $mac_addr;
function MacAddInfo($os_type) {
switch (strtolower ( $os_type )) {
case "linux" :
$this->forLinux ();
break;
case "solaris" :
break;
case "unix" :
break;
case "aix" :
break;
default :
$this->forWindows ();
break;
}
$temp_array = array ();
foreach ( $this->return_array as $value ) {
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 )) {
$this->mac_addr = $temp_array [0];
break;
}
}
unset ( $temp_array );
return $this->mac_addr;
}
function forWindows() {
@exec ( "ipconfig /all", $this->return_array );
if ($this->return_array)
return $this->return_array;
else {
$ipconfig = $_SERVER ["WINDIR"] . "/system32/ipconfig.exe";
if (is_file ( $ipconfig ))
@exec ( $ipconfig . " /all", $this->return_array );
else
@exec ( $_SERVER ["WINDIR"] . "/system/ipconfig.exe /all", $this->return_array );
return $this->return_array;
}
}
function forLinux() {
@exec ( "ifconfig -a", $this->return_array );
return $this->return_array;
}
}
//調(diào)用示例
//$mac = new MacAddInfo(PHP_OS);
//echo $mac->mac_addr;
?>
您可能感興趣的文章:
- 推薦一款MAC OS X 下php集成開(kāi)發(fā)環(huán)境mamp
- mac下安裝nginx和php
- mac環(huán)境中使用brew安裝php5.5.15
- php實(shí)現(xiàn)獲取局域網(wǎng)所有用戶的電腦IP和主機(jī)名、及mac地址完整實(shí)例
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php獲取服務(wù)器端mac和客戶端mac的地址支持WIN/LINUX
- Mac下搭建php開(kāi)發(fā)環(huán)境教程
- PHP獲取MAC地址的函數(shù)代碼
- mac下Apache + MySql + PHP搭建網(wǎng)站開(kāi)發(fā)環(huán)境
- mac下多個(gè)php版本快速切換的方法
相關(guān)文章
PHP中使用file_get_contents post數(shù)據(jù)代碼例子
這篇文章主要介紹了PHP中使用file_get_contents post數(shù)據(jù)代碼例子,本文直接給出代碼實(shí)例,需要的朋友可以參考下2015-02-02在服務(wù)端進(jìn)行目錄建立、刪除,文件上傳、刪除的過(guò)程的php代碼
下面的php代碼具有查看服務(wù)器端目錄和文件,刪除文件夾等操作,是學(xué)習(xí)php文件操作不錯(cuò)的參考資料2008-09-09PHP實(shí)現(xiàn)生成透明背景的PNG縮略圖函數(shù)分享
這篇文章主要介紹了PHP實(shí)現(xiàn)生成透明背景的PNG縮略圖函數(shù)分享,需要的朋友可以參考下2014-07-07ThinkPHP表單數(shù)據(jù)智能寫(xiě)入create方法實(shí)例分析
這篇文章主要介紹了ThinkPHP表單數(shù)據(jù)智能寫(xiě)入create方法,以實(shí)例形式較為詳細(xì)的分析了ThinkPHP中create只能寫(xiě)入的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09PHP編寫(xiě)學(xué)校網(wǎng)站上新生注冊(cè)登陸程序的實(shí)例分享
這篇文章主要介紹了使用PHP編寫(xiě)學(xué)校網(wǎng)站上新生注冊(cè)登陸程序的實(shí)例分享,只包括簡(jiǎn)單的數(shù)據(jù)庫(kù)信息錄入和查詢等步驟的一些關(guān)鍵點(diǎn),需要的朋友可以參考下2016-03-03