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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BadotzCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WinPEAuthor Commented:
awesome thanks dude
0
BadotzCommented:
No worries - glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.