Hi Guys,
I found this code online that works for 99.9 % of the computer in my network. But for one system it doesn't get the correct ip, it return 0.0.0.0. Which tells me it is pulling the ip from a network adapter disabled or not active, and since the codes only looks at the first adapter it stops there. For 99.9% of the system on my network this code pulls the correct IP from the correct adapter. I guess I have to make it more robust so that it pulls it pulls the local network LAN adapter Any suggestions on how to do this efficiently? and so that it works on all machines(win xp, vista, win 7).
Thanks
I found this code online that works for 99.9 % of the computer in my network. But for one system it doesn't get the correct ip, it return 0.0.0.0. Which tells me it is pulling the ip from a network adapter disabled or not active, and since the codes only looks at the first adapter it stops there. For 99.9% of the system on my network this code pulls the correct IP from the correct adapter. I guess I have to make it more robust so that it pulls it pulls the local network LAN adapter Any suggestions on how to do this efficiently? and so that it works on all machines(win xp, vista, win 7).
Thanks
Code:
' Look at IP and act accordingly.
strcomputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
strCount = 1
For Each objitem in colitems
If strCount = 1 Then
ActiveDHCPIPAddress = objitem.IPAddress(0)
'strIPAddress = Join(objitem.IPAddress, ",")
IP = stripaddress
strCount = strCount + 1
wscript.echo IP
Else
End If
next