VBSCRIPT - Get IP address, how is it storing in the array. How to extract XXX.XXX.XXX.

Can someone explain this code to me a little better, I understand that it pulls from the network adapters class and grabs all not null ip addresses. I see then that it stores it in a ran, but not familiar enough with arrays, I dont understand how hes doing it.


Bottom line, I need to extract the first three octects of this data. The XXX.XXX.XXX, so that I can do a subnet compare afterwards. Unfortunatly I have failed, im guessing b/c I dont really understand how its storing it in the first place.

I have to use this IP schema code. Thanks in advance.
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",,48)
	i = -1
	For Each objItem in colItems
	    i = i + 1
		ReDim Preserve arrNetadapter_Description(i), arrNetadapter_MACAddress(i)
		ReDim Preserve arrNetadapter_DNSHostName(i)
		ReDim Preserve arrNetadapter_DHCPEnabled(i)
		ReDim Preserve arrNetadapter_DHCPServer(i)
		ReDim Preserve arrNetadapter_DNS(i)
		ReDim Preserve arrNetadapter_WINSPrimaryServer(i)
		ReDim Preserve arrNetadapter_WINSSecondaryServer(i)
	    arrNetadapter_Description(i) = objItem.Description
	    arrNetadapter_MACAddress(i) = objItem.MACAddress
	    arrNetadapter_DNSHostName(i) = objItem.DNSHostName
		arrNetadapter_DHCPEnabled(i) = objItem.DHCPEnabled
	    arrNetadapter_DHCPServer(i) = objItem.DHCPServer
	    arrNetadapter_DNS(i) = objItem.DNSDomain
	    arrNetadapter_WINSPrimaryServer(i) = objItem.WINSPrimaryServer
	    arrNetadapter_WINSSecondaryServer(i) = objItem.WINSSecondaryServer
		If Not IsNull(objItem.IPAddress) Then
			For j = 0 To UBound(objItem.IPAddress)
				If (j > UBound(arrNetadapter_IPAddress,2)) Then
					ReDim Preserve arrNetadapter_IPAddress(nMaxNetworkAdapters,j)
				End If
				arrNetadapter_IPAddress(i,j) = objItem.IPAddress(j)
		End If

Open in new window

WinPEAsked:
Who is Participating?
 
BadotzConnect With a Mentor Commented:
The variable is a collection (Dictionary object). Each element is available using either it's index or name. The IP addresses are stored in arrNetadapter_IPAddress(i,j), where "i" is the maximum number of network adapters (I'm guessing) and "j" is the index of the actual IP address.

As far as getting the first portion of the IP address, try this:

' Assume arrNetadapter_IPAddress(i,j) = "255.254.253.252"

Dim x() As String
x = Split(arrNetadapter_IPAddress(i,j), ".")

"x" will contain:

x(0) = 255
x(1) = 254
x(2) = 253
x(3) = 252
0
 
WinPEAuthor Commented:
awesome thanks dude
0
 
BadotzCommented:
No worries - glad to help.
0
All Courses

From novice to tech pro — start learning today.