Copy Code code as follows:
<?php
/**
Obtain the MAC address origin of the NIC; currently supports Win/linux system
Get the physical (MAC) address of the machine's network card
**/
Class getmacaddr{
var $return _array = Array (); Returns an array of strings with a MAC address
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;
}
}
Method uses
$mac = new Getmacaddr (php_os);
Echo $mac->mac_addr; Here is the real MAC address of the machine, please comment out
?>