JS obtains the local IP address and MAC address

Source: Internet
Author: User

JS obtains the local IP address and MAC address

1. ActiveX Control

View plaincopy to clipboardprint? <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); alert (unescape (IPAddr); // document.forms%0%.txt DNSName. value = unescape (sDNSName); // doc Ument. 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 = 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, 'wi N32_NetworkAdapterConfiguration '); </SCRIPT> <FORM id = formfoo name = formbar action = NICPost. asp method = post> <INPUT value = 00: 05: 5D: 0E: C7: FA name = txtMACAddr> <INPUT value = 192.168.0.2 name = txtIPAddr> <INPUT value = typ name = txtDNSName> </FORM> </BODY> </HTML> <HEAD> <TITLE> WMI Scripting HTML </TITLE> <META http-equiv = Content-Type content = "text/html; charset = gb2312 "> <SCRIPT language = JScript event =" OnC Ompleted (hResult, pErrorObject, pAsyncContext) "for = foo> // document.forms%0%.txt MACAddr. value = unescape (MACAddr); document.forms%0%.txt IPAddr. value = unescape (IPAddr); alert (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> <FORM id = formfoo name = formbar action = NICPost. asp method = post>

<INPUT value = 00: 05: 5D: 0E: C7: FA name = txtMACAddr> <INPUT value = 192.168.0.2 name = txtIPAddr> <INPUT value = typ name = txtDNSName> </FORM> </BODY> </HTML>

2. Call the doscommand

View plaincopy to clipboardprint? <Html> <mce: script type = "text/javascript"> <! -- GetIP = function () {var fso = new ActiveXObject ("Scripting. fileSystemObject "); var wsh = new ActiveXObject (" WScript. shell "); wsh. run ("command.com/c ipconfig/all> C: \ ip.txt"); var f = fso. openTextFile ("C: \ ip.txt"); var s = f. readAll (); f. close (); document. write (s); alert (s. match (/IP Address (\.) + \ :( (\ d {1, 3 }\.) {3} (\ d {1, 3})/) [0]);} // --> </mce: script> <body>

 

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.