php獲取網(wǎng)卡的MAC地址支持WIN/LINUX系統(tǒng)
更新時間:2014年04月30日 15:49:48 作者:
這篇文章主要介紹了使用php獲取網(wǎng)卡的MAC地址支持WIN/LINUX系統(tǒng),需要的朋友可以參考下
復制代碼 代碼如下:
<?php
/**
獲取網(wǎng)卡的MAC地址原碼;目前支持WIN/LINUX系統(tǒng)
獲取機器網(wǎng)卡的物理(MAC)地址
**/
class GetMacAddr{
var $return_array = array(); // 返回帶有MAC地址的字串數(shù)組
var $mac_addr;
function GetMacAddr($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;
}
}
//方法使用
$mac = new GetMacAddr(PHP_OS);
echo $mac->mac_addr; //這里是機器的真實MAC地址,請注釋掉
?>
相關文章
PHP輸出XML格式數(shù)據(jù)的方法總結(jié)
這篇文章主要介紹了PHP輸出XML格式數(shù)據(jù)的方法,結(jié)合實例形式總結(jié)分析了php常用的xml格式數(shù)據(jù)輸出相關操作技巧,需要的朋友可以參考下2017-02-02PHP編程實現(xiàn)csv文件導入mysql數(shù)據(jù)庫的方法
這篇文章主要介紹了PHP編程實現(xiàn)csv文件導入mysql數(shù)據(jù)庫的方法,涉及php文件讀取、轉(zhuǎn)換、數(shù)據(jù)庫的連接、插入等相關操作技巧,需要的朋友可以參考下2017-04-04PHP API接口必備之輸出json格式數(shù)據(jù)示例代碼
這篇文章主要給大家介紹了關于PHP API接口必備之輸出json格式數(shù)據(jù)的相關資料文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面來一起看看吧。2017-06-06php安全開發(fā) 添加隨機字符串驗證,防止偽造跨站請求
偽造跨站請求比較難以防范,而且危害巨大,攻擊者可以通過這種方式惡作劇,發(fā)spam信息,刪除數(shù)據(jù)等等。那怎么防范偽造跨站攻擊呢2013-02-02