Don't say much nonsense, just go to the code!
Copy CodeThe code is as follows:
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.
Copy the Code code as follows:
Only applicable to IE browser, and there will be alarm prompts, very regrettable.
http://www.bkjia.com/PHPjc/328054.html www.bkjia.com true http://www.bkjia.com/PHPjc/328054.html techarticle don't say much nonsense, just go to the code! Copy the code as follows:? PHP class Macaddr {public $returnArray = array (), public $macAddr, function __contruct ($os _type=null) {if (is_ Nu ...