Get Servermac
<?php/** Obtain the MAC address source of the network card, the physical (MAC) address that supports Win/linux system to obtain the machine card now **/class getmacaddr{var $result = array ();//Return with MA C-Address string array var $macAddr; /* Construct */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 System Get method */function For_linux_os () {@exec ("ifconfig-a", $this->result); return $this->result; } The Get method in the/*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 Clientmac Address:
@exec ("Arp-a", $array); Run the ARP-A command and put the result into the array $array in the foreach ($array as $value) { //Match results are placed into 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 acquired by the client cannot be tested on this machine and can only be used by other computers to access the output
PHP Gets the address of server-side Mac and Clientmac