This article mainly introduces how to get the client's MAC address in PHP and JS separately, the need for friends can refer to the following
Don't say much nonsense, just go to the code!
Copy CodeThe code is as follows:
<?php
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 "<br/>";
Get Client
Linux
$command = "Arp-a {$_server[' remote_addr ']}";
Echo $command;
echo "<br/>";
$result = ' {$command} ';
Windows
$command = "Nbtstat-a {$_server[' remote_addr ']}";
Echo $command;
echo "<br/>";
$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 CodeThe code is as follows:
<script language= "JScript" event= "oncompleted (Hresult,perrorobject, Pasynccontext)" for= "foo" >
Document.forms[0].lbmacaddr.value=unescape (MACADDR);
</script>
<script language= "JScript" event= "OnObjectReady (objobject,objasynccontext)" for= "foo" >
if (objobject.ipenabled! = NULL && objobject.ipenabled! = "undefined" && objobject.ipenabled = = True & & objobject.macaddress! = NULL && objobject.macaddress! = "undefined") macaddr = objobject.macaddress;
</script>
<object id= "locator" classid= "Clsid:76a64158-cb41-11d1-8b02-00600806d9b6" ></object>
<object id= "foo" classid= "clsid:75718c9a-f029-11d1-a1ac-00c04fb6c223" ></object>
<script language= "JScript" >
var service = Locator. ConnectServer ();
var macaddr;
var ipaddr;
var domainaddr;
var sdnsname;
Service. Security_. impersonationlevel=3;
Service. Instancesofasync (foo, ' Win32_NetworkAdapterConfiguration ');
</script>
<form><input type= "text" id= ' lbmacaddr ' name= ' lbmacaddr '/></form>
Only applicable to IE browser, and there will be alarm prompts, very regrettable.
PHP/JS get the implementation code for the client MAC address