MAC address is the network card address is generally unable to get to the user's MAC address, because the security restrictions on the browser so it is almost impossible to obtain, the following two pieces of code for everyone to play.
Example 1
PHP Code:
The code is as follows |
Copy Code |
@exec ("Arp-a", $array); Executes the ARP-A command, and the result is placed in the array $array echo ""; Print_r ($array); Prints the obtained array foreach ($array as $value) { if (//match result put to array $mac_array 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; Output Client Mac ?> |
Example 2
The code is as follows |
Copy Code |
Class Macaddr { Public $returnArray = Array (); Public $macAddr; function __contruct ($os _type=null) { if (Is_null ($os _type)) $os _type = Php_os; 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->returnarray 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; } function Forwindows () { @exec ("Ipconfig/all", $this->returnarray); if ($this->returnarray) return $this->returnarray; else{ $ipconfig = $_server["windir"]. " System32ipconfig.exe "; if (Is_file ($ipconfig)) @exec ($ipconfig. "/all", $this->returnarray); Else @exec ($_server["windir"]. " Systemipconfig.exe/all ", $this->returnarray); return $this->returnarray; } } function Forlinux () { @exec ("Ifconfig-a", $this->returnarray); return $this->returnarray; } } $mac = new Macaddr (php_os); Echo $mac->macaddr; echo " "; Get Client Linux $command = "Arp-a {$_server[' remote_addr ']}"; Echo $command; echo " "; $result = ' {$command} '; Windows $command = "Nbtstat-a {$_server[' remote_addr ']}"; Echo $command; echo " "; $result = ' {$command} '; Print_r ($result); ?> |
There is no big problem getting the logic on the server side, there may be permissions issues.
When the client is fetched, it may be slow and the Arp/nbstat command execution will be slow.
The code is as follows |
Copy Code |
|
Only applicable to IE browser, and there will be alarm prompt
http://www.bkjia.com/PHPjc/632908.html www.bkjia.com true http://www.bkjia.com/PHPjc/632908.html techarticle MAC address is the network card address is generally unable to get to the user's MAC address, because the security restrictions on the browser so it is almost impossible to obtain, the following take two code to everyone ...