Win32_NetworkAdapterConfiguration - WMI sample in Python

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)

import win32com.client
def WMIDateStringToDate(dtmDate):
    strDateTime = ""
    if (dtmDate[4] == 0):
        strDateTime = dtmDate[5] + '/'
    else:
        strDateTime = dtmDate[4] + dtmDate[5] + '/'
    if (dtmDate[6] == 0):
        strDateTime = strDateTime + dtmDate[7] + '/'
    else:
        strDateTime = strDateTime + dtmDate[6] + dtmDate[7] + '/'
        strDateTime = strDateTime + dtmDate[0] + dtmDate[1] + dtmDate[2] + dtmDate[3] + " " + dtmDate[8] + dtmDate[9] + ":" + dtmDate[10] + dtmDate[11] +':' + dtmDate[12] + dtmDate[13]
    return strDateTime

strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")
for objItem in colItems:
    if objItem.ArpAlwaysSourceRoute != None:
        print "ArpAlwaysSourceRoute:" + ` objItem.ArpAlwaysSourceRoute`
    if objItem.ArpUseEtherSNAP != None:
        print "ArpUseEtherSNAP:" + ` objItem.ArpUseEtherSNAP`
    if objItem.Caption != None:
        print "Caption:" + ` objItem.Caption`
    if objItem.DatabasePath != None:
        print "DatabasePath:" + ` objItem.DatabasePath`
    if objItem.DeadGWDetectEnabled != None:
        print "DeadGWDetectEnabled:" + ` objItem.DeadGWDetectEnabled`
    print "DefaultIPGateway:"
    strList = " "
    try :
        for objElem in objItem.DefaultIPGateway :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    if objItem.DefaultTOS != None:
        print "DefaultTOS:" + ` objItem.DefaultTOS`
    if objItem.DefaultTTL != None:
        print "DefaultTTL:" + ` objItem.DefaultTTL`
    if objItem.Description != None:
        print "Description:" + ` objItem.Description`
    if objItem.DHCPEnabled != None:
        print "DHCPEnabled:" + ` objItem.DHCPEnabled`
    if objItem.DHCPLeaseExpires != None:
        print "DHCPLeaseExpires:" + WMIDateStringToDate(objItem.DHCPLeaseExpires)
    if objItem.DHCPLeaseObtained != None:
        print "DHCPLeaseObtained:" + WMIDateStringToDate(objItem.DHCPLeaseObtained)
    if objItem.DHCPServer != None:
        print "DHCPServer:" + ` objItem.DHCPServer`
    if objItem.DNSDomain != None:
        print "DNSDomain:" + ` objItem.DNSDomain`
    print "DNSDomainSuffixSearchOrder:"
    strList = " "
    try :
        for objElem in objItem.DNSDomainSuffixSearchOrder :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    if objItem.DNSEnabledForWINSResolution != None:
        print "DNSEnabledForWINSResolution:" + ` objItem.DNSEnabledForWINSResolution`
    if objItem.DNSHostName != None:
        print "DNSHostName:" + ` objItem.DNSHostName`
    print "DNSServerSearchOrder:"
    strList = " "
    try :
        for objElem in objItem.DNSServerSearchOrder :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    if objItem.DomainDNSRegistrationEnabled != None:
        print "DomainDNSRegistrationEnabled:" + ` objItem.DomainDNSRegistrationEnabled`
    if objItem.ForwardBufferMemory != None:
        print "ForwardBufferMemory:" + ` objItem.ForwardBufferMemory`
    if objItem.FullDNSRegistrationEnabled != None:
        print "FullDNSRegistrationEnabled:" + ` objItem.FullDNSRegistrationEnabled`
    print "GatewayCostMetric:"
    strList = " "
    try :
        for objElem in objItem.GatewayCostMetric :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    if objItem.IGMPLevel != None:
        print "IGMPLevel:" + ` objItem.IGMPLevel`
    if objItem.Index != None:
        print "Index:" + ` objItem.Index`
    if objItem.InterfaceIndex != None:
        print "InterfaceIndex:" + ` objItem.InterfaceIndex`
    print "IPAddress:"
    strList = " "
    try :
        for objElem in objItem.IPAddress :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    if objItem.IPConnectionMetric != None:
        print "IPConnectionMetric:" + ` objItem.IPConnectionMetric`
    if objItem.IPEnabled != None:
        print "IPEnabled:" + ` objItem.IPEnabled`
    if objItem.IPFilterSecurityEnabled != None:
        print "IPFilterSecurityEnabled:" + ` objItem.IPFilterSecurityEnabled`
    if objItem.IPPortSecurityEnabled != None:
        print "IPPortSecurityEnabled:" + ` objItem.IPPortSecurityEnabled`
    print "IPSecPermitIPProtocols:"
    strList = " "
    try :
        for objElem in objItem.IPSecPermitIPProtocols :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    print "IPSecPermitTCPPorts:"
    strList = " "
    try :
        for objElem in objItem.IPSecPermitTCPPorts :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    print "IPSecPermitUDPPorts:"
    strList = " "
    try :
        for objElem in objItem.IPSecPermitUDPPorts :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    print "IPSubnet:"
    strList = " "
    try :
        for objElem in objItem.IPSubnet :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    if objItem.IPUseZeroBroadcast != None:
        print "IPUseZeroBroadcast:" + ` objItem.IPUseZeroBroadcast`
    if objItem.IPXAddress != None:
        print "IPXAddress:" + ` objItem.IPXAddress`
    if objItem.IPXEnabled != None:
        print "IPXEnabled:" + ` objItem.IPXEnabled`
    print "IPXFrameType:"
    strList = " "
    try :
        for objElem in objItem.IPXFrameType :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    if objItem.IPXMediaType != None:
        print "IPXMediaType:" + ` objItem.IPXMediaType`
    print "IPXNetworkNumber:"
    strList = " "
    try :
        for objElem in objItem.IPXNetworkNumber :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    if objItem.IPXVirtualNetNumber != None:
        print "IPXVirtualNetNumber:" + ` objItem.IPXVirtualNetNumber`
    if objItem.KeepAliveInterval != None:
        print "KeepAliveInterval:" + ` objItem.KeepAliveInterval`
    if objItem.KeepAliveTime != None:
        print "KeepAliveTime:" + ` objItem.KeepAliveTime`
    if objItem.MACAddress != None:
        print "MACAddress:" + ` objItem.MACAddress`
    if objItem.MTU != None:
        print "MTU:" + ` objItem.MTU`
    if objItem.NumForwardPackets != None:
        print "NumForwardPackets:" + ` objItem.NumForwardPackets`
    if objItem.PMTUBHDetectEnabled != None:
        print "PMTUBHDetectEnabled:" + ` objItem.PMTUBHDetectEnabled`
    if objItem.PMTUDiscoveryEnabled != None:
        print "PMTUDiscoveryEnabled:" + ` objItem.PMTUDiscoveryEnabled`
    if objItem.ServiceName != None:
        print "ServiceName:" + ` objItem.ServiceName`
    if objItem.SettingID != None:
        print "SettingID:" + ` objItem.SettingID`
    if objItem.TcpipNetbiosOptions != None:
        print "TcpipNetbiosOptions:" + ` objItem.TcpipNetbiosOptions`
    if objItem.TcpMaxConnectRetransmissions != None:
        print "TcpMaxConnectRetransmissions:" + ` objItem.TcpMaxConnectRetransmissions`
    if objItem.TcpMaxDataRetransmissions != None:
        print "TcpMaxDataRetransmissions:" + ` objItem.TcpMaxDataRetransmissions`
    if objItem.TcpNumConnections != None:
        print "TcpNumConnections:" + ` objItem.TcpNumConnections`
    if objItem.TcpUseRFC1122UrgentPointer != None:
        print "TcpUseRFC1122UrgentPointer:" + ` objItem.TcpUseRFC1122UrgentPointer`
    if objItem.TcpWindowSize != None:
        print "TcpWindowSize:" + ` objItem.TcpWindowSize`
    if objItem.WINSEnableLMHostsLookup != None:
        print "WINSEnableLMHostsLookup:" + ` objItem.WINSEnableLMHostsLookup`
    if objItem.WINSHostLookupFile != None:
        print "WINSHostLookupFile:" + ` objItem.WINSHostLookupFile`
    if objItem.WINSPrimaryServer != None:
        print "WINSPrimaryServer:" + ` objItem.WINSPrimaryServer`
    if objItem.WINSScopeID != None:
        print "WINSScopeID:" + ` objItem.WINSScopeID`
    if objItem.WINSSecondaryServer != None:
        print "WINSSecondaryServer:" + ` objItem.WINSSecondaryServer`