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.