Using JS to obtain the IP address and MAC of the IE client does not seem to be able to do B/S structure of the system, we often need to obtain some client information, such as IP and MAC, for identity authentication. In ASP. NET, it is easy to get the MAC address of the server, but it is really easy to get the MAC address of the client. The common practice is to call Win32API or directly call the nbtstat command, there are a lot of problems with this, and the other method is to directly use the client script. Here we use Javascript. The advantage of this is that it does not need to be processed by the server, but can be obtained by the client itself, it is passed to the server, and the speed and reliability are better than those obtained on the server.
The specific implementation of html and javascript is 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%.txt MACAddr. value = unescape (MACAddr); document.forms%0%.txt IPAddr. value = unescape (IPAddr); document.forms%0%.txt DNSName. 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> </HEAD> <BODY> <OBJECT id = locator classid = CLSID: extends 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 </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
The key is to use two ActiveX:
However, these two ActiveX methods are provided by the system and do not need to be downloaded or registered.
The next job is to use scripts to interact with ActiveX. The script can be js or Vbs. I personally like to use js.