WMI and IPAddresses

  • Thread starter Raymond Balaian
  • Start date
R

Raymond Balaian

Hi all, hope this is the right place for this.

I have our workstations set up to run system startup scripts to get the
IPAddress of the client, and its behaving stragely when the computer has a
wired NIC and a wireless NIC.

Here is the code:
-----------------------------------
Set activeIPConfigSet = GetObject("winmgmts:").ExecQuery ("select IPAddress,
IPSubnet from Win32_NetworkAdapterConfiguration where IPEnabled=true")
For Each ipConfig in activeIPConfigSet
For i = LBound(ipConfig.IPAddress) to UBound(ipConfig.IPAddress)
tmpIP = ipConfig.ipAddress(i)
If tmpIP <> "0.0.0.0" AND Left(tmpIP,4) <> "169." Then
IPAddress = tmpIP
Exit For
Else
IPAddress = "0.0.0.0"
End If
Next
Next
-----------------------------------

Here is what happens:

Wireless and Wired BOTH enabled - IPAddress = 0.0.0.0
Wired Enabled only - IPAddress = 10.10.10.10 (or any good IP)
Wireless Enabled only - IPAddress = 0.0.0.0

Is there something I'm missing here?

Thanks,
Ray
 
S

Scott McNairy \(MVP\)

Just a guess, but perhaps the adapter in question is busy aquiring the IP
Address when the script runs.
 
R

Raymond Balaian

I thought about that, but the startup script comes off the sysvol on the
domain controller, so it would have to have a IP'd nic to talk to the DC.

rb
 
S

Scott McNairy \(MVP\)

Try this copy of your script out (minor differences)

Set activeIPConfigSet = GetObject("winmgmts:").ExecQuery ("select IPAddress,
IPSubnet from Win32_NetworkAdapterConfiguration where IPEnabled=true")

For Each ipConfig in activeIPConfigSet
For i = LBound(ipConfig.IPAddress) to UBound(ipConfig.IPAddress)
tmpIP = ipConfig.ipAddress(i)
If tmpIP <> "0.0.0.0" AND Left(tmpIP,4) <> "169." Then
IPAddress = tmpIP
wscript.echo IPAddress
End If
Next
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top