Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI IPAddress Query

Status
Not open for further replies.

brianashman

Technical User
Dec 11, 2003
15
US
Is there a way to write a WMI query such that it finds only the network adapters w/IP addresses that are not blank & TCP/IP is enabled? Since the IPAdrress is an Array of addresses, the following doesn't work:

select * from win32_Networkadapterconfiguration where IPEnabled=true and IPAddress<>''

I am hoping there is a way to represent an empty array in the query.
 
Hello brianashman,

Check in your environment see if this query fulfills your need.
Code:
select * from win32_NetworkAdapterConfiguration where IPEnabled=true and DHCPEnabled=true
regards - tsuji
 
No, it doesn't.

I have a laptop w/a wireless network PCMCIA card & a integrated NIC. I have both set to use DHCP, but usually only 1 will be in use (i.e. if I am wireless, I won't use a CAT5 cable). So, both show up w/DHCP being enabled. The unused adapter has an empty IPAddress array.

If I am on the internet by dialup, the IPAddress array isn't empty but DHCP is not enabled (also, subnet mask is reported as 255.255.255.255... don't exactly know that works... I have MSN for dial up.)

So, I would still like the query to refer to the IPAddress array, I am usuing the following currently as a workaround:

<code>
Dim strComputer, CRLF
Dim colDrives, strMsg
Dim WSHNetwork

strComputer = "."
CRLF = Chr(13) & Chr(10)
Set NetworkPROP = WScript.CreateObject("WScript.Network")
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True")

For Each objAdapter in colAdapters
If objAdapter.IPAddress(0)<>"" then
Msgbox "UserName " & Chr(9) & "= " & NetworkPROP.UserName & CRLF & _
"Host name: " & Chr(9) & "= " & ucase(objAdapter.DNSHostName) & CRLF & _
"IP address: " & Chr(9) & "= " & objAdapter.IPAddress(0) & CRLF & _
"IP subnet: " & Chr(9) & "= " & objAdapter.IPSubnet(0) & CRLF & _
"Description: " & Chr(9) & "= " & objAdapter.Description & CRLF & _
"User Domain: " & Chr(9) & "= " & NetworkPROP.UserDomain & CRLF & _
"Physical address: " & Chr(9) & "= " & objAdapter.MACAddress & CRLF & _
"DHCP enabled: " & Chr(9) & "= " & objAdapter.DHCPEnabled, _
vbinformation + vbOKOnly + vbmsgboxsetforeground, _
"Network Properties"
end if
Next
</code>

Thanx for the effort.
 
Further notes:

For non-wql filtering, you can always do by checking .IPAddress(0). Hence, this filtering scheme would be something like this.
Code:
set svc=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_Networkadapterconfiguration where IPEnabled=true"
set cNAC_ipe=svc.execquery(sQuery)
for each oNAC_ipe in cNAC_ipe
    if oNAC_ipe.IPAddress<>"" then
        'do something
    else
        'do something or nothing
next
regards - tsuji
 
brianoshman,

I posted the above without seeing your feedback. But, I think it is a viable alternative. I have a mistake upthere in typing up. This is the correction.
Code:
for each oNAC_ipe in cNAC_ipe
    if oNAC_ipe.IPAddress(0)<>"" then
        'do something
    else
        'do something or nothing
next
- tsuji
 
errata:

I leftout again end if. So I just recap all.
Code:
set svc=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_NetworkAdapterConfiguration where IPEnabled=true"
set cNAC_ipe=svc.execquery(sQuery)
for each oNAC_ipe in cNAC_ipe
    if oNAC_ipe.IPAddress(0)<>"" then
        'do something
    else
        'do something or nothing
    end if
next
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top