php獲取服務(wù)器端mac和客戶端mac的地址支持WIN/LINUX
更新時(shí)間:2014年05月15日 09:36:10 作者:
這篇文章主要介紹了php獲取服務(wù)器端mac和客戶端mac地址的方法,需要的朋友可以參考下
獲取服務(wù)器mac
<?php
/**
獲取網(wǎng)卡的MAC地址原碼;目前支持WIN/LINUX系統(tǒng)
獲取機(jī)器網(wǎng)卡的物理(MAC)地址
**/
class GetmacAddr{
var $result = array(); // 返回帶有MAC地址的字串?dāng)?shù)組
var $macAddr;
/*構(gòu)造*/
function __construct($osType){
switch ( strtolower($osType) ){
case "unix": break;
case "solaris": break;
case "aix": break;
case "linux": {
$this->for_linux_os();
}break;
default: {
$this->for_windows_os();
}break;
}
$temp_array = array();
foreach($this->result 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->macAddr = $temp_array[0];
break;
}
}
unset($temp_array);
return $this->macAddr;
}
/*linux系統(tǒng)中獲取方法*/
function for_linux_os(){
@exec("ifconfig -a", $this->result);
return $this->result;
}
/*win系統(tǒng)中的獲取方法*/
function for_windows_os(){
@exec("ipconfig /all", $this->result);
if ( $this->result ) {
return $this->result;
} else {
$ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";
if(is_file($ipconfig)) {
@exec($ipconfig." /all", $this->result);
} else {
@exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->result);
return $this->result;
}
}
}
}
?>
獲取客戶端mac地址:
@exec("arp -a",$array); //執(zhí)行arp -a命令,結(jié)果放到數(shù)組$array中
foreach($array as $value){
//匹配結(jié)果放到數(shù)組$mac_array
if(strpos($value,$_SERVER["REMOTE_ADDR"]) && preg_match("/(:?[0-9A-F]{2}[:-]){5}[0-9A-F]{2}/i",$value,$mac_array)){
$mac = $mac_array[0];
break;
}
}
echo $mac;
注:客戶端獲取的mac不能在本機(jī)測試,只能用別的電腦訪問才能輸出
復(fù)制代碼 代碼如下:
<?php
/**
獲取網(wǎng)卡的MAC地址原碼;目前支持WIN/LINUX系統(tǒng)
獲取機(jī)器網(wǎng)卡的物理(MAC)地址
**/
class GetmacAddr{
var $result = array(); // 返回帶有MAC地址的字串?dāng)?shù)組
var $macAddr;
/*構(gòu)造*/
function __construct($osType){
switch ( strtolower($osType) ){
case "unix": break;
case "solaris": break;
case "aix": break;
case "linux": {
$this->for_linux_os();
}break;
default: {
$this->for_windows_os();
}break;
}
$temp_array = array();
foreach($this->result 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->macAddr = $temp_array[0];
break;
}
}
unset($temp_array);
return $this->macAddr;
}
/*linux系統(tǒng)中獲取方法*/
function for_linux_os(){
@exec("ifconfig -a", $this->result);
return $this->result;
}
/*win系統(tǒng)中的獲取方法*/
function for_windows_os(){
@exec("ipconfig /all", $this->result);
if ( $this->result ) {
return $this->result;
} else {
$ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";
if(is_file($ipconfig)) {
@exec($ipconfig." /all", $this->result);
} else {
@exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->result);
return $this->result;
}
}
}
}
?>
獲取客戶端mac地址:
復(fù)制代碼 代碼如下:
@exec("arp -a",$array); //執(zhí)行arp -a命令,結(jié)果放到數(shù)組$array中
foreach($array as $value){
//匹配結(jié)果放到數(shù)組$mac_array
if(strpos($value,$_SERVER["REMOTE_ADDR"]) && preg_match("/(:?[0-9A-F]{2}[:-]){5}[0-9A-F]{2}/i",$value,$mac_array)){
$mac = $mac_array[0];
break;
}
}
echo $mac;
注:客戶端獲取的mac不能在本機(jī)測試,只能用別的電腦訪問才能輸出
您可能感興趣的文章:
- PHP程序員簡單的開展服務(wù)治理架構(gòu)操作詳解(一)
- PHP 服務(wù)器配置(使用Apache及IIS兩種方法)
- PHP 顯示客戶端IP與服務(wù)器IP的代碼
- PHP實(shí)現(xiàn)Socket服務(wù)器的代碼
- php獲取服務(wù)器信息的實(shí)現(xiàn)代碼
- php socket客戶端及服務(wù)器端應(yīng)用實(shí)例
- PHP向socket服務(wù)器收發(fā)數(shù)據(jù)的方法
- 利用php獲取服務(wù)器時(shí)間的實(shí)現(xiàn)代碼
- PHP實(shí)現(xiàn)服務(wù)器狀態(tài)監(jiān)控的方法
- PHP程序員簡單的開展服務(wù)治理架構(gòu)操作詳解(二)
相關(guān)文章
PHP+AJAX實(shí)現(xiàn)無刷新注冊(帶用戶名實(shí)時(shí)檢測)
PHP+AJAX實(shí)現(xiàn)無刷新注冊(帶用戶名實(shí)時(shí)檢測)...2007-01-01PHP中file_put_contents追加和換行的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狿HP中file_put_contents追加和換行的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04PHP中實(shí)現(xiàn)漢字轉(zhuǎn)區(qū)位碼應(yīng)用源碼實(shí)例解析
PHP里如何實(shí)現(xiàn)漢字轉(zhuǎn)區(qū)位碼這個(gè)問題一直困擾這大多程序員,那么下面這個(gè)源碼實(shí)例相信能給大家?guī)砗艽蟮膸椭?/div> 2010-06-06慎用preg_replace危險(xiǎn)的/e修飾符(一句話后門常用)
要確保 replacement 構(gòu)成一個(gè)合法的 PHP 代碼字符串,否則 PHP 會在報(bào)告在包含 preg_replace() 的行中出現(xiàn)語法解析錯(cuò)誤2013-06-06php-perl哈希算法實(shí)現(xiàn)(times33哈希算法)
php-perl哈希實(shí)現(xiàn)算法–DJBX33A(Daniel J. Bernstein, Times 33 with Addition)APR哈希默認(rèn)算法2013-12-12PHP采用get獲取url漢字出現(xiàn)亂碼的解決方法
這篇文章主要介紹了PHP采用get獲取url漢字出現(xiàn)亂碼的解決方法,是很多PHP程序員都曾遇到的問題,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-11-11最新評論