js| clients 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. In ASP.net, it's easy to get a server-side Mac, but it takes a lot of effort to get the MAC address of the client, usually by calling Win32API or calling the nbtstat command directly, and there are many problems with that, 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:
<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 action=nicpost.asp method=post><input VALUE=00:05:5D:0E:C7:FA > <input value=192.168.0.2 name=txtipaddr> <input Value=typ name=txtdnsname> </FORM></BODY ></HTML>
The key is to use two ActiveX:
<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 task is to use scripting and ActiveX interaction, the script can be JS or vbs I personally like to use JS.