PHP獲取MAC地址的具體實例
更新時間:2013年12月13日 16:25:58 作者:
分享一例php取得機器mac地址的代碼,學習下php讀取硬件信息的方法,此代碼適用于windows、linux系統(tǒng)。有需要的朋友參考學習下
本節(jié)分享的php代碼,主要功能:
獲取機器網(wǎng)卡的物理(MAC)地址。
代碼:
復制代碼 代碼如下:
<?php
/**
* 獲取機器網(wǎng)卡的物理(MAC)地址
* 目前支持WIN/LINUX系統(tǒng)
**/
class MacAddInfo {
var $return_array = array (); // 返回帶有MAC地址的字串數(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;
?>
您可能感興趣的文章:
相關(guān)文章
PHP中使用file_get_contents post數(shù)據(jù)代碼例子
這篇文章主要介紹了PHP中使用file_get_contents post數(shù)據(jù)代碼例子,本文直接給出代碼實例,需要的朋友可以參考下2015-02-02在服務端進行目錄建立、刪除,文件上傳、刪除的過程的php代碼
下面的php代碼具有查看服務器端目錄和文件,刪除文件夾等操作,是學習php文件操作不錯的參考資料2008-09-09PHP實現(xiàn)生成透明背景的PNG縮略圖函數(shù)分享
這篇文章主要介紹了PHP實現(xiàn)生成透明背景的PNG縮略圖函數(shù)分享,需要的朋友可以參考下2014-07-07ThinkPHP表單數(shù)據(jù)智能寫入create方法實例分析
這篇文章主要介紹了ThinkPHP表單數(shù)據(jù)智能寫入create方法,以實例形式較為詳細的分析了ThinkPHP中create只能寫入的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09