php 获取服务器端mac地址,客户端mac地址
2016-09-14 09:35
253 查看
//服务器端mac获取
<?php
/**
获取网卡的MAC地址原码;目前支持WIN/LINUX系统
获取机器网卡的物理(MAC)地址
**/
class GetmacAddr{
var $result = array(); // 返回带有MAC地址的字串数组
var $macAddr;
/*构造*/
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系统中获取方法*/
function for_linux_os(){
@exec("ifconfig -a", $this->result);
return $this->result;
}
/*win系统中的获取方法*/
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); //执行arp -a命令,结果放到数组$array中
foreach($array as $value){
//匹配结果放到数组$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;
<?php
/**
获取网卡的MAC地址原码;目前支持WIN/LINUX系统
获取机器网卡的物理(MAC)地址
**/
class GetmacAddr{
var $result = array(); // 返回带有MAC地址的字串数组
var $macAddr;
/*构造*/
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系统中获取方法*/
function for_linux_os(){
@exec("ifconfig -a", $this->result);
return $this->result;
}
/*win系统中的获取方法*/
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); //执行arp -a命令,结果放到数组$array中
foreach($array as $value){
//匹配结果放到数组$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;
相关文章推荐
- php如何获取服务器端mac与客户端mac地址
- PHP获取服务器端唯一值MAC地址
- PHP获取客户端和服务器端IP
- PHP获取客户端和服务器端IP
- PHP获取客户端及服务器端IP的封装类
- php获取页面地址(带GET参数)、客户端ip、服务器端ip
- PHP获取客户端和服务器端IP
- php获取客户端ip和服务器端ip
- 服务器端通过arp协议获取客户端mac地址
- php获取客户端和服务器端ip
- php获取服务器端mac和客户端mac的地址支持WIN/LINUX
- JAVA/PHP服务器端获取客户端IP
- php获取客户端IP和服务器端IP
- 客户端和服务器端的IP、MAC地址等的获取
- 使用PHP在局域网中获取客户端 计算机名 IP地址 MAC地址
- 使用PHP在局域网中获取客户端 计算机名 IP地址 MAC地址
- 服务器端和客户端IP地址及MAC地址获取
- php获取客户端IP和php获取服务器端IP
- PHP获取客户端及服务器端IP的封装类
- PHP获取客户端和服务器端IP