In the B/s structure of the system, we often need to obtain some information on the client, such as IP and Mac, in conjunction with authentication. Getting a server-side Mac is easy, but getting the client's MAC address takes a lot of effort, usually by calling Win32API or calling the nbtstat command directly, which has many problems, and the other way is to use client script directly, We use JavaScript here, the advantage of this is that there is no need for server-side processing, there is a client to obtain, passed to the server side, and speed and reliability than on the server to get better.
the concrete implementations of HTML and JavaScript are as follows:
Copy Code code as follows:
<HTML>
<HEAD>
<TITLE>WMI Scripting Html</title>
<meta http-equiv=content-type content= "text/html; charset=gb2312 ">
<script language=jscript event= "oncompleted (Hresult,perrorobject, Pasynccontext)" for=foo>
Document.forms[0].txtmacaddr.value=unescape (MACADDR);
Document.forms[0].txtipaddr.value=unescape (IPADDR);
Document.forms[0].txtdnsname.value=unescape (Sdnsname);
Document.formbar.submit ();
</SCRIPT>
<script language=jscript Event=onobjectready (objobject,objasynccontext) for=foo>
if (objobject.ipenabled!= null && objobject.ipenabled!= "undefined" && objobject.ipenabled = = True)
{
if (objobject.macaddress!= null && objobject.macaddress!= "undefined")
MACADDR = objobject.macaddress;
if (objobject.ipenabled && objobject.ipaddress (0)!= null && objobject.ipaddress (0)!= "undefined")
ipaddr = objobject.ipaddress (0);
if (objobject.dnshostname!= null && objobject.dnshostname!= "undefined")
Sdnsname = Objobject.dnshostname;
}
</SCRIPT>
<meta content= "MSHTML 6.00.2800.1106" name=generator><BODY>
<object Id=locator Classid=clsid:76a64158-cb41-11d1-8b02-00600806d9b6 viewastext></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 Id=formfoo Name=formbar method=post>
<input type= "Text" name=txtmacaddr>
<input type= "Text" name=txtipaddr>
<input type= "Text" name=txtdnsname>
</FORM>
</BODY>
</HTML>
In fact, the most important thing is to use two ActiveX:
Copy Code code as follows:
<object Id=locator Classid=clsid:76a64158-cb41-11d1-8b02-00600806d9b6 viewastext></object>
<object Id=foo classid=clsid:75718c9a-f029-11d1-a1ac-00c04fb6c223></object>
However, these two ActiveX systems are self-contained and do not need to be downloaded or registered.
The next step is to use scripting and ActiveX interactions, which can be either JS or VBS.