Home >Backend Development >PHP Tutorial >Implementation code for php/js to obtain client mac address_PHP tutorial

Implementation code for php/js to obtain client mac address_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:00:35925browse

Without further ado, let’s get straight to the code!

Copy code The 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();
                                                                   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)){                                                         
unset($temp_array);
          return $this->macAddr;                                                                                                             ($this->returnArray)
return $this->returnArray;
else{
$ipconfig = $_SERVER["WINDIR"]."system32ipconfig.exe";
If (is_file ($ipconfig))
             @exec($ipconfig." /all", $this->returnArray);                                                                all ", $ this- & gt; returnarray);
return $ this-& gt; reTurnArray;
}
}

Function forlinux () {
@exec (" iFconfig-" a", $this->returnArray);
returnArray;
}
}

$mac = new MacAddr(PHP_OS);
echo $ mac->macAddr;
echo "
";

// Get the 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 in getting the server-side logic, but there may be permission issues.
When obtaining the client, it may be slow, and the execution of the arp/nbstat command will be slow.

Copy code The code is as follows:



< /form>



Only applicable to IE browser, and there will be a warning prompt, which is a pity.

http://www.bkjia.com/PHPjc/328054.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/328054.htmlTechArticle Without further ado, let’s get straight to the code! Copy the code The code is as follows: ?php class MacAddr { public $returnArray = array(); public $macAddr; function __contruct($os_type=null){ if(is_nu...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn