[2008] WMI Network Information (IP Address)
Hello, Still on the WMI problems :-)
I am trying to get the IP address of each machine using the WMI because I am using WMI for other stuff its just easyier to do it all through that.
I have the correct command to get IP address information but when it runs it comes up with lots, this is only a sample of what it has brought up on my pc:
Code:
-----------------------------------
Win32_NetworkAdapterConfiguration instance
-----------------------------------
IPAddress:
-----------------------------------
Win32_NetworkAdapterConfiguration instance
-----------------------------------
IPAddress:
-----------------------------------
Win32_NetworkAdapterConfiguration instance
-----------------------------------
IPAddress:
-----------------------------------
Win32_NetworkAdapterConfiguration instance
-----------------------------------
IPAddress:
-----------------------------------
Win32_NetworkAdapterConfiguration instance
-----------------------------------
IPAddress:
-----------------------------------
Win32_NetworkAdapterConfiguration instance
-----------------------------------
IPAddress: 10.10.1.63
-----------------------------------
Win32_NetworkAdapterConfiguration instance
-----------------------------------
IPAddress:
-----------------------------------
Win32_NetworkAdapterConfiguration instance
-----------------------------------
IPAddress:
-----------------------------------
Win32_NetworkAdapterConfiguration instance
-----------------------------------
Now all the machines in the Network are going to start with the IP address 10.10.1.x so is there anyway I can filter the results and get only the bit I am looking for so for instance from this one my IP address would return: 10.10.1.63
Thanks,
Max
Re: [2008] WMI Network Information (IP Address)
Try changing the code from...
Code:
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_NetworkAdapterConfiguration instance")
Console.WriteLine("-----------------------------------")
If queryObj("IPAddress") Is Nothing Then
Console.WriteLine("IPAddress: {0}", queryObj("IPAddress"))
Else
Dim arrIPAddress As String()
arrIPAddress = queryObj("IPAddress")
For Each arrValue As String In arrIPAddress
Console.WriteLine("IPAddress: {0}", arrValue)
Next
End If
Next
to...
Code:
For Each queryObj As ManagementObject in searcher.Get()
If Not(queryObj("IPAddress") Is Nothing) Then
Dim arrIPAddress As String()
arrIPAddress = queryObj("IPAddress")
For Each arrValue As String In arrIPAddress
Console.WriteLine(arrValue)
Next
End If
Next
Re: [2008] WMI Network Information (IP Address)
Hi thanks for the info almost there but not quite,
It works almost but also picks up two ip addresses of:
0.0.0.0
So my final output is:
0.0.0.0
0.0.0.0
10.10.1.63
And for my program to work I can only have the one address. I tried changing the line:
If Not (queryObj("IPAddress") Is Nothing) Then
To:
If Not (queryObj("IPAddress") Is Nothing Or queryObj("IPAddress") Is "0.0.0.0") Then
but it still displays the 0.0.0.0's. Have you got a fix for this?
Thanks,
Max
and a few variations but that is not valid
Re: [2008] WMI Network Information (IP Address)
Try...
Code:
For Each arrValue As String In arrIPAddress
If arrValue <> "0.0.0.0" Then
Console.WriteLine(arrValue)
End If
Next
This won't help you if there are more than one valid IP address.
Re: [2008] WMI Network Information (IP Address)
Ok thanks for the info I am just trying to play with that and get it working because at the moment it is only coming back with one ip but its coming back with 0.0.0.0
For the sake of trying to make it easyier is their another way of getting an IP address rather than WMI where I can state that I only want an IP address returned if it begins with 10.10.1 ? because the front end will not be different.
Thanks,
Max