Sign in to follow this  
Followers 0
MrBeatnik

WMI IP data

6 posts in this topic

Using the normal VB converted WMI queries, I can get information on my NICs.

The two following queries work fine, and return information:

$colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
$colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress = '00:A1:FF:45:89:BA'")

However, the following code does not provide any information:

$colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPAddress = 192.168.0.1")

I have tried various combinations of quotes etc around the IP address, but no joy at all. Does anyone have any suggestions on how to return the NIC info from the IP address? Note, the IP address is correct - I have also used the var @IPAddress1 and still no joy.

Original code (note I have cut down the consolewrites - I would actually be writing more info to the console than this code does):

#include <date.au3>

Dim $strComputer = @IPAddress1
Dim $objWMIService, $colAdapters, $n
Dim $utcLeaseObtained, $utcLeaseObtained, $utcLeaseExpired,  $strLeaseObtained, $utcLeaseExpires, $strLeaseExpires


 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

 $colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") 

$n = 1

 
For $objAdapter in $colAdapters
   ConsoleWrite ("Network Adapter " & $n & @CR)
   ConsoleWrite ("================="& @CR)
   ConsoleWrite ("  Description: " & $objAdapter.Description& @CR)
 
   ConsoleWrite ("  Physical (MAC) address: " & $objAdapter.MACAddress& @CR)
   ConsoleWrite ("  Host name:            " & $objAdapter.DNSHostName& @CR)
 
   If Not ($objAdapter.IPAddress) = " " Then
      For $i = 0 To UBound($objAdapter.IPAddress)
         ConsoleWrite ("  IP address " & ($i) & ":           " & $objAdapter.IPAddress($i)& @CR)
      Next
   EndIf
 
   If Not ($objAdapter.IPSubnet) = " " Then
      For $i = 0 To UBound($objAdapter.IPSubnet)
         ConsoleWrite ("  Subnet:                " & $objAdapter.IPSubnet($i)& @CR)
      Next
   EndIf
 
   $n = $n + 1
 
Next

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can´t query IPAddress. IPAddress is a array

For $i = 0 To UBound($objAdapter.IPAddress)
         ConsoleWrite ("  IP address " & ($i) & ":           " & $objAdapter.IPAddress($i)& @CR)
      Next

Try this

$objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2")
If Not IsObj($objWMIService) Then Exit 

$colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For $objAdapter in $colAdapters
   If Not ($objAdapter.IPAddress) = " " Then
      For $i = 0 To UBound($objAdapter.IPAddress)
        If $objAdapter.IPAddress($i) == "192.168.0.1" Then
            ConsoleWrite ("  IP address " & ($i) & ":             " & $objAdapter.IPAddress($i)& @CR)
            ConsoleWrite ("  Physical (MAC) address: " & $objAdapter.MACAddress& @CR)
        EndIf
      Next
   EndIf
Next
Edited by Tec

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can´t query IPAddress. IPAddress ist a array

For $i = 0 To UBound($objAdapter.IPAddress)
         ConsoleWrite ("  IP address " & ($i) & ":           " & $objAdapter.IPAddress($i)& @CR)
      Next

I haven't tried the VB scripts, but there are quite a few examples in the VB world of using the query I am trying (WHERE IPAddress = xxx).

Do you mean:

a ) The VB scripts are wrong and you simply cannot query on IP address?

b ) Autoit cannot query on IP address even though VB script can?

c ) The ConsoleWrite output would not work because an array is not being returned by the query?

As far as I was aware, the WMI query returns an array of all NIC info (IP, DNS, Subnet mask etc) based on the search criteria.

I'm a little confused why I could search by MAC, but not by IP - as far as I am aware both details are in the "DB".

For $i = 0 To UBound($objAdapter.IPAddress)
         ConsoleWrite ("  IP address " & ($i) & ":           " & $objAdapter.IPAddress($i)& @CR)
      Next
This code works fine for all queries except the one I am asking about.

---

EDIT

---

Just saw your additional info.

I am aware that I could search the output of each NIC to see if the IP matches.

I was just hoping that there was an cleaner option since I saw the (WHERE IPAddress = xxx) in the VB scripting world...

Edited by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You query Win32_NetworkAdapterConfiguration. The MACAddress is unique for the NetworkAdapter. So only one MACAddress for NetworkAdapter but your NetworkAdapter can have more the one IPAddress. So IPAddress is a Array. MACAddress is a String.

IPAddress[0] = IPaddress1

IPAddress[1] = IPaddress2

IPAddress[2] = IPaddress3

.

.

.

$colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPAddress[0]='192.168.0.1'")

But WHERE IPAddress[0]='192.168.0.1' is not working here.

http://www.tech-archive.net/Archive/window...1/msg00287.html

Arman, sorry to say but that will not work, the IPAddress property is not a string, rather an array of strings and that is not supported with LIKE using WQL, the reason it is an array being that you can have multiple IP addresses on a single NIC, or even IPv4 and IPv6 addresses on the same one. You need to figure out another value to query for to make your filter work.

Edited by Tec

Share this post


Link to post
Share on other sites

Sorry, I read your original post wrong... I thought you said it wasn't an array...

Ok. Thanks for your help Tec!


Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites

Sorry for my bad english :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0