0

In need of a vbscript to grab the laptop or desktop local IP address, while ignoring things such as local adapters that are NOT actively in use. Ignoring adapters with no gateway set, or no mac address.

Have tried the below but unable to get proper result, as I also have an adapter that has no gateway and it pulls that one... How to ignore?

strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > '' AND IPEnabled = 'True'"

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If IsArray( objItem.IPAddress ) Then
        If UBound( objItem.IPAddress ) = 0 Then
            strIP = "IP Address: " & objItem.IPAddress(0)
        Else
            strIP = "IP Addresses: " & Join( objItem.IPAddress, ",   IPv6: " )
        End If
    End If
Next

I have tried adding "AND DefaultIPGateway > ''" to the query but this fails and returns nothing.

MBF
  • 336
  • 1
  • 4
  • 17
  • 1
    The answer is here - [WQL in filter doesn't work](https://stackoverflow.com/a/35113241) - "Note WQL does not support queries of array datatypes." - Ref [Querying with WQL @ MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/aa392902(v=vs.85).aspx). Instead, loop through the results and use `Join()` on the `DefaultIPGateway` property to check the string using the `Len()` function. – user692942 Jan 10 '23 at 19:30

0 Answers0