Javascript uses WMI to obtain client Nic Information

Source: Internet
Author: User
Tags keep alive

This article is reproduced

You need to obtain the network card information of the client. You have tried many methods, such as using VC to write ActiveX controls. However, you need to sign the control, otherwise, if the security level of the IE browser is relatively high, the control may be prompted frequently.

In addition, it is very likely that it cannot run. In addition, VBScript can also be used to obtain information about the client Nic, and the code will be attached later. However, using this method, ie may prompt that it cannot 'create object ', no good solutions are found.

Finally, a simple and effective method is found, that is, the required information is obtained by using the javascriptswbemlocator object to operate WMI win32_networkadapterconfiguration.

What is WMI?

WMI is the core of the Windows 2 k/XP management system. WMI is a useful plug-in for other Win32 operating systems. WMI is based on cimom, and cimom is the common

Information Model Object Manager) is an object database that describes the operating system components. It provides a public interface for MMC and script programs to access the operating system components. With WMI

Different APIs are not required when tool software and script programs access different parts of the operating system. On the contrary, WMI can be inserted into different parts of the operating system, tool software and WMI can easily read and write WMI, so no

Only javascript can connect to WMI, VBScript, C #, and other languages.


What is win32_networkadapterconfiguration?


Win32_networkadapterconfiguration describes the attributes and behavior of a network adapter. This includes additional attributes and methods that support TCP/IP management and IPX protocol independent from the network adapter.
The following is a brief translation of the main attributes and methods of win32_networkadapterconfiguration from msdn. For more information, see
Http://msdn.microsoft.com/en

-

US/library/aa394217 (vs.85). aspx
Class win32_networkadapterconfiguration: cim_setting
{
Boolean arpalwayssourceroute;
Boolean arpuseethersnap;
String Caption; // cim_setting object description, which is inherited from cim_setting
String databasepath;
Boolean deadgwdetectenabled;
String defaultipgateway []; // default gateway. Note that this type is an array.
Uint8 defaulttos;
Uint8 defaultttl; // default TTL value of the IP Address Header
String description; // the description of the cim_setting object. This attribute is inherited from cim_setting.
Boolean dhcpenabled; // whether DHCP is allowed. If DHCP server can assign an address when establishing a network connection
Datetime dhcpleaseexpires; // DHCP lease Validity Period
Datetime dhcpleaseobtained; // time for obtaining DHCP lease
String dhcpserver; // DHCP server
String dnsdomain; // DHCP server domain
String dnsdomainsuffixsearchorder [];
Boolean dnsenabledforwinsresolution;
String dnshostname;
String dnsserversearchorder [];
Boolean domaindnsregistrationenabled;
Uint32 forwardbuffermemory;
Boolean fulldnsregistrationenabled;
Uint16 gatewaycostmetric [];
Uint8 igmplevel;
Uint32 index;
Uint32 interfaceindex;
String IPaddress []; // ip address, which is an array
Uint32 ipconnectionmetric;
Boolean ipenabled; // whether TCP/IP is activated on the network adapter
Boolean ipfiltersecurityenabled;
Boolean ipportsecurityenabled;
String ipsecpermitipprotocols [];
String ipsecpermittcpports [];
String ipsecpermitudpports [];
String ipsubnet []; // subnet mask, for example, "255.255.0.0"
Boolean ipusezerobroadcast;
String ipxaddress; // IPX address
Boolean ipxenabled; // whether IPX is allowed
Uint32 ipxframetype [];
Uint32 ipxmediatype;
String ipxnetworknumber [];
String ipxvirtualnetnumber;
Uint32 keepaliveinterval;
Uint32 KeepAliveTime;
String macaddress;
Uint32 MTU; // The maximum transmission unit.
Uint32 numforwardpackets;
Boolean pmtubhdetectenabled;
Boolean pmtudiscoveryenabled;
String servicename;
String settingid;
Uint32 tcpipnetbiosoptions;
Uint32 tcpmaxconnectretransmissions;
Uint32 TCPMaxDataRetransmissions;
Uint32 tcpnumconnections;
Boolean tcpuserfc1122urgentpointer;
Uint16 tcpwindowsize;
Boolean winsenablelmhostslookup;
String winshostlookupfile;
String winsprimaryserver;
String winsscopeid;
String winssecondaryserver;
};
Main Method

Disableipsec
IPSec is disabled on the master TCP/IP network adapter.

Enabledhcp
Enable DHCP

Enabledns
Enable DNS

Enableipfiltersec
Enable ipfiltersec

Enableipsec
Enable IPSec.

Enablestatic
Apply static TCP/IP addressing to the target network adapter

Enablewins
Enable wins, but independent from the network adapter.

Releasedhcplease
Release IP addresses bound to DHCP-enabled network adapters

Releasedhcpleaseall
Release all IP addresses bound to DHCP-enabled network adapters.

Renewdhcplease
IP address bound to the DHCP-Enabled Network Adapter

Renewdhcpleaseall
All IP addresses bound to DHCP-enabled network adapters of renews

Setarpalwayssourceroute

Setarpuseethersnap
Use 802.3 snap encoding to allow Ethernet packets

Setdatabasepath
Set the path (hosts, LmHosts, networks, and Protocols) of the standard Internet data file ).

Setdeadgwdetect
Enable Dead Gateway Detection.

Setdefatos TOS
(Obsolete)

Setdefaultttl
Set the default TTL value

Setdnsdomain
Set DNS domain name.

Setdnsserversearchorder
Set the DNS server search sequence

Setdnssuffixsearchorder

Setdynamicdnsregistration

Setforwardbuffermemory

Setgateways
Set Gateway

Setigmplevel
Set IGMP level

Setipconnectionmetric
Set routing metric.

Setipxframetypenetworkpairs

Setkeepalivetime

Set the time for TCP to verify whether an idle connection is available by sending a keep alive packet

Setmtu
Setting the maximum transmission unit MTU is no longer supported

Setnumforwardpackets

Set the number of IP packet headers allocated to the route packet data packet queue
Setpmtubhdetect
Allows black hole routers detection.

Setpmtudiscovery
MTU discovery is allowed.

Settcpipnetbios

Set NetBIOS operations on TCP/IP
Windows 2000 and Windows NT 4.0: This attribute is not available

Settcpmaxconnectretransmissions
Set the number of TCP attempts to resend connection requests

Settcpmaxdataretransmissions
Sets the number of times TCP will retransmit an individual data segment before aborting the connection.

Settcpnumconnections
Maximum number of concurrent TCP connections.

Settcpuserfc1122urgentpointer
Specifies whether the rfc1122 specification is used for TCP or the mode used by the BSD system.

Settcpwindowsize
Set the TCP window size.

Setwinsserver
Set the WINS Server

Operation Code

JavaScript code

<Script language = "JavaScript">
<! --

Function getadapterinfo (){

VaR locator = new activexobject ("wbemscripting. swbemlocator ");
VaR service = locator. connectserver ("."); // connect to the local server
VaR properties = service. execquery ("select * From win32_networkadapterconfiguration ");
// Use SQL standards for queries
VaR E = new enumerator (properties );

For (;! E. atend (); E. movenext ())
{
VaR P = E. Item ();

Document. Write ("caption:" + P. Caption + ""); // Nic description. You can also use description
Document. Write ("IP:" + P. IPaddress (0) + ""); // the IP address is of the array type. The subnet and default gateway are the same.
Document. Write ("net mask:" + P. ipsubnet (0) + "");
Document. Write ("Default Gateway:" + P. defaultipgateway (0) + "");
Document. Write ("Mac:" + P. macaddress + ""); // Nic physical address
Document. Write ("<HR> ");
}

}

Getadapterinfo ();

// -->
</SCRIPT>
Put the above Code in the HTML code to view the details of JS output. For more details, see the attributes listed above.
If multiple NICs are installed on the machine and only one Nic is desired, you can use the query and filter method to obtain the NIC with Intel and RealTek installed, to obtain the RealTek Nic, you only need to use SQL query as follows:
VaR properties = service. execquery ("select * From win32_networkadapterconfiguration where description like '% RealTek % '");

VBScript code

Strcomputer = "."
Set ob1_miservice = GetObject (_
"Winmgmts: //" & strcomputer & "/root/cimv2 ")
Set ipconfigset = obw.miservice. execquery _
("Select IPaddress from win32_networkadapterconfiguration "_
& "Where description like '% RealTek % '")

For each ipconfig in ipconfigset
If not isnull (ipconfig. IPaddress) then
For I = lbound (ipconfig. IPaddress )_
To ubound (ipconfig. IPaddress)
Wscript. Echo ipconfig. IPaddress (I)
Next
End if
Next
Save the preceding text as test. vbs and double-click it.

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.