How to Use JS to obtain the IP address and MAC of the IE client does not seem to be possible _ javascript skills

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.