VB/WMI script to get IP information(without reading registry)
Here is a VB script to use the Win32_NetworkAdapter class and the NetconnectionID property to determine the MAC address of the active network connection. Then use the Win32_NetworkAdapterconfiguration class to find the IP address associated with the MAC address.
The netConnectionID property is not available in Windows 2000/NT. I will post a workaround in the next couple of days.
The script has the similar function as the one I posted yesterday and only this time we don’t have to deal with registry.
on Error resume next
strComputer = "."
Set objWMIService = GetObject(_
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter " _
& "Where NetConnectionID = " & _
"'Local Area Connection'")
For Each objNetAdapter in colNetAdapters
strMACAddress = objNetAdapter.MACAddress
Next
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
If objItem.MACAddress = strMACAddress Then
For Each strDefaultIPGateway in objItem.DefaultIPGateway
Wscript.Echo "DefaultIPGateway: " & strDefaultIPGateway
Next
End If
Next