Get the server mac
Copy code The code is as follows:
/**
Get the original MAC address of the network card; currently supports WIN/LINUX system
Get the physical (MAC) address of the machine's network card
**/
class GetmacAddr{
var $result = array(); // Returns a string array with MAC address
var $macAddr;
/*Construction*/
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;
}
/*Getting method in linux system*/
function for_linux_os(){
@exec("ifconfig -a", $this->result);
return $this->result;
}
/*Getting method in win system*/
function for_windows_os(){
@exec("ipconfig /all", $this->result);
if ( $this->result ) {
return $this->result;
} else {
$ipconfig = $_SERVER["WINDIR"]."system32ipconfig.exe";
if(is_file($ipconfig)) {
@exec($ipconfig." /all", $this->result );
} else {
@exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->result);
return $this->result;
}
}
}
}
?>
Get the client mac address:
Copy code The code is as follows:
@exec("arp -a",$array); //Execute the arp -a command and put the result into the array $array
foreach ($array as $value){
//The matching results are placed in the array $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;
Note: The mac obtained by the client cannot be tested on this machine and can only be output by accessing it from another computer.
http://www.bkjia.com/PHPjc/770587.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/770587.htmlTechArticleGet the server mac. Copy the code as follows: ?php /**Obtain the original MAC address of the network card; currently supports WIN/LINUX system. Obtain the physical (MAC) address of the machine's network card **/ class GetmacAddr{...