Win32_NetworkAdapterConfiguration - WMI sample in JScript

The foundations for Manageability in Windows 7/2008/Vista/XP/2000 and Millennium Edition/'98 are Windows Management Instrumentation (WMI; formerly WBEM) and WMI extensions for Windows Driver Model (WDM).

ActiveXperts Network Monitor provides the ability to build monitor check routines based on WMI. ActiveXperts has collected more than a hundred WMI samples. You can use these samples as a base for new check routines you can write yourself.

On this site, you can find many WMI samples.


Win32_NetworkAdapterConfiguration

Description

The Win32_NetworkAdapterConfiguration WMI class represents the attributes and behaviors of a network adapter. This class has been extended to include extra properties and methods that support the management of the TCP/IP and Internetworking Packet Exchange (IPX) protocols (and are independent of the network adapter).

Example(s)

var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;

var arrComputers = new Array("DELL17");
for (i = 0; i < arrComputers.length; i++) {
   WScript.Echo();
   WScript.Echo("==========================================");
   WScript.Echo("Computer: " + arrComputers[i]);
   WScript.Echo("==========================================");

   var objWMIService = GetObject("winmgmts:\\\\" + arrComputers[i] + "\\root\\CIMV2");
   var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL",
                                          wbemFlagReturnImmediately | wbemFlagForwardOnly);

   var enumItems = new Enumerator(colItems);
   for (; !enumItems.atEnd(); enumItems.moveNext()) {
      var objItem = enumItems.item();

      WScript.Echo("ArpAlwaysSourceRoute: " + objItem.ArpAlwaysSourceRoute);
      WScript.Echo("ArpUseEtherSNAP: " + objItem.ArpUseEtherSNAP);
      WScript.Echo("Caption: " + objItem.Caption);
      WScript.Echo("DatabasePath: " + objItem.DatabasePath);
      WScript.Echo("DeadGWDetectEnabled: " + objItem.DeadGWDetectEnabled);
      try { WScript.Echo("DefaultIPGateway: " + (objItem.DefaultIPGateway.toArray()).join(",")); }
         catch(e) { WScript.Echo("DefaultIPGateway: null"); }
      WScript.Echo("DefaultTOS: " + objItem.DefaultTOS);
      WScript.Echo("DefaultTTL: " + objItem.DefaultTTL);
      WScript.Echo("Description: " + objItem.Description);
      WScript.Echo("DHCPEnabled: " + objItem.DHCPEnabled);
      WScript.Echo("DHCPLeaseExpires: " + WMIDateStringToDate(objItem.DHCPLeaseExpires));
      WScript.Echo("DHCPLeaseObtained: " + WMIDateStringToDate(objItem.DHCPLeaseObtained));
      WScript.Echo("DHCPServer: " + objItem.DHCPServer);
      WScript.Echo("DNSDomain: " + objItem.DNSDomain);
      try { WScript.Echo("DNSDomainSuffixSearchOrder: " + (objItem.DNSDomainSuffixSearchOrder.toArray()).join(",")); }
         catch(e) { WScript.Echo("DNSDomainSuffixSearchOrder: null"); }
      WScript.Echo("DNSEnabledForWINSResolution: " + objItem.DNSEnabledForWINSResolution);
      WScript.Echo("DNSHostName: " + objItem.DNSHostName);
      try { WScript.Echo("DNSServerSearchOrder: " + (objItem.DNSServerSearchOrder.toArray()).join(",")); }
         catch(e) { WScript.Echo("DNSServerSearchOrder: null"); }
      WScript.Echo("DomainDNSRegistrationEnabled: " + objItem.DomainDNSRegistrationEnabled);
      WScript.Echo("ForwardBufferMemory: " + objItem.ForwardBufferMemory);
      WScript.Echo("FullDNSRegistrationEnabled: " + objItem.FullDNSRegistrationEnabled);
      try { WScript.Echo("GatewayCostMetric: " + (objItem.GatewayCostMetric.toArray()).join(",")); }
         catch(e) { WScript.Echo("GatewayCostMetric: null"); }
      WScript.Echo("IGMPLevel: " + objItem.IGMPLevel);
      WScript.Echo("Index: " + objItem.Index);
      WScript.Echo("InterfaceIndex: " + objItem.InterfaceIndex);
      try { WScript.Echo("IPAddress: " + (objItem.IPAddress.toArray()).join(",")); }
         catch(e) { WScript.Echo("IPAddress: null"); }
      WScript.Echo("IPConnectionMetric: " + objItem.IPConnectionMetric);
      WScript.Echo("IPEnabled: " + objItem.IPEnabled);
      WScript.Echo("IPFilterSecurityEnabled: " + objItem.IPFilterSecurityEnabled);
      WScript.Echo("IPPortSecurityEnabled: " + objItem.IPPortSecurityEnabled);
      try { WScript.Echo("IPSecPermitIPProtocols: " + (objItem.IPSecPermitIPProtocols.toArray()).join(",")); }
         catch(e) { WScript.Echo("IPSecPermitIPProtocols: null"); }
      try { WScript.Echo("IPSecPermitTCPPorts: " + (objItem.IPSecPermitTCPPorts.toArray()).join(",")); }
         catch(e) { WScript.Echo("IPSecPermitTCPPorts: null"); }
      try { WScript.Echo("IPSecPermitUDPPorts: " + (objItem.IPSecPermitUDPPorts.toArray()).join(",")); }
         catch(e) { WScript.Echo("IPSecPermitUDPPorts: null"); }
      try { WScript.Echo("IPSubnet: " + (objItem.IPSubnet.toArray()).join(",")); }
         catch(e) { WScript.Echo("IPSubnet: null"); }
      WScript.Echo("IPUseZeroBroadcast: " + objItem.IPUseZeroBroadcast);
      WScript.Echo("IPXAddress: " + objItem.IPXAddress);
      WScript.Echo("IPXEnabled: " + objItem.IPXEnabled);
      try { WScript.Echo("IPXFrameType: " + (objItem.IPXFrameType.toArray()).join(",")); }
         catch(e) { WScript.Echo("IPXFrameType: null"); }
      WScript.Echo("IPXMediaType: " + objItem.IPXMediaType);
      try { WScript.Echo("IPXNetworkNumber: " + (objItem.IPXNetworkNumber.toArray()).join(",")); }
         catch(e) { WScript.Echo("IPXNetworkNumber: null"); }
      WScript.Echo("IPXVirtualNetNumber: " + objItem.IPXVirtualNetNumber);
      WScript.Echo("KeepAliveInterval: " + objItem.KeepAliveInterval);
      WScript.Echo("KeepAliveTime: " + objItem.KeepAliveTime);
      WScript.Echo("MACAddress: " + objItem.MACAddress);
      WScript.Echo("MTU: " + objItem.MTU);
      WScript.Echo("NumForwardPackets: " + objItem.NumForwardPackets);
      WScript.Echo("PMTUBHDetectEnabled: " + objItem.PMTUBHDetectEnabled);
      WScript.Echo("PMTUDiscoveryEnabled: " + objItem.PMTUDiscoveryEnabled);
      WScript.Echo("ServiceName: " + objItem.ServiceName);
      WScript.Echo("SettingID: " + objItem.SettingID);
      WScript.Echo("TcpipNetbiosOptions: " + objItem.TcpipNetbiosOptions);
      WScript.Echo("TcpMaxConnectRetransmissions: " + objItem.TcpMaxConnectRetransmissions);
      WScript.Echo("TcpMaxDataRetransmissions: " + objItem.TcpMaxDataRetransmissions);
      WScript.Echo("TcpNumConnections: " + objItem.TcpNumConnections);
      WScript.Echo("TcpUseRFC1122UrgentPointer: " + objItem.TcpUseRFC1122UrgentPointer);
      WScript.Echo("TcpWindowSize: " + objItem.TcpWindowSize);
      WScript.Echo("WINSEnableLMHostsLookup: " + objItem.WINSEnableLMHostsLookup);
      WScript.Echo("WINSHostLookupFile: " + objItem.WINSHostLookupFile);
      WScript.Echo("WINSPrimaryServer: " + objItem.WINSPrimaryServer);
      WScript.Echo("WINSScopeID: " + objItem.WINSScopeID);
      WScript.Echo("WINSSecondaryServer: " + objItem.WINSSecondaryServer);
   }
}

function WMIDateStringToDate(dtmDate)
{
   if (dtmDate == null)
   {
      return "null date";
   }
   var strDateTime;
   if (dtmDate.substr(4, 1) == 0)
   {
      strDateTime = dtmDate.substr(5, 1) + "/";
   }
   else
   {
      strDateTime = dtmDate.substr(4, 2) + "/";
   }
   if (dtmDate.substr(6, 1) == 0)
   {
      strDateTime = strDateTime + dtmDate.substr(7, 1) + "/";
   }
   else
   {
      strDateTime = strDateTime + dtmDate.substr(6, 2) + "/";
   }
   strDateTime = strDateTime + dtmDate.substr(0, 4) + " " +
   dtmDate.substr(8, 2) + ":" +
   dtmDate.substr(10, 2) + ":" +
   dtmDate.substr(12, 2);
   return(strDateTime);
}