Get Server Mac
Copy CodeThe code is as follows:
/**
Obtain the MAC address source of the network card; currently supports Win/linux system
Get the physical (MAC) address of the machine card
**/
Class getmacaddr{
var $result = array (); Returns an array of strings with MAC addresses
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;
}
How to obtain the/*linux system */
function For_linux_os () {
@exec ("Ifconfig-a", $this->result);
return $this->result;
}
Acquisition method in/*win system */
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;
}
}
}
}
?>
Get the client MAC address:
Copy CodeThe code is as follows:
@exec ("Arp-a", $array); Executes the ARP-A command, and the result is placed in the array $array
foreach ($array as $value) {
Match result put to 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 acquired by the client cannot be tested natively and can only be exported with a different computer access
http://www.bkjia.com/PHPjc/770587.html www.bkjia.com true http://www.bkjia.com/PHPjc/770587.html techarticle get the server Mac copy code code as follows: PHP/** gets the MAC address source of the network card, the physical (MAC) address of the Win/linux system to get the machine card is **/class getmacaddr{...