Visual Basic - I need to work with a List of things - an array, something. But my brain is Practical and the examples of ArrayList, List(of things), Dictionaries, etc. all are just creating the list, not working with it. So, problem is I need to Run IPConfig /all and pull that into the program, then go through it and make something (array? list of things?) that will let me go back and reference items in the list... Nic1.Name = Eth0 ; Nic1.MediaState = Disconnected ; Nic1.Description = Intel Adapter ; Nic1.PhysicalAddress = 00.3f.dc.3f.qt ... etc... Nic2, Nic3, etc.
Then work with it as ... Select Nic where nic.name like "ethernet" - put nic.dhcpenabled value in listbox1, etc. (yes, I do more powershell than visual basic these days)
I've got a Class set up:
Public Class Nics
Public Property Name As String
Public Property MediaState As String
Public Property Description As String
Public Property PhysicalAddress As String
Public Property DHCPEnabled As String
Public Property IPv4 As String
Public Property DefaultGateway As String
Public Property DNSServer1 As String
Public Property NetBiosoverTcpIP As String
End Class
and am pulling in the results of the ipconfig /all to an array of lines
Dim cOutput As String
Using oStreamReader As System.IO.StreamReader = cProcess.StandardOutput
cOutput = oStreamReader.ReadToEnd()
End Using
Dim aIpConfig() As String = cOutput.Split(Environment.NewLine)
and go into a For Each to parse the lines...
Dim mNics As New List(Of Nics) ' ???
For Each vLine In aIpConfig
' MsgBox(vLine)
' Build out an array with each NIC and it's info...
If vLine Like "Host Name*" Then
Dim anHN() As String = vLine.Split(":")
Dim nHostName As String = anHN(1)
NICListInfo.Items.Add("Host Name: " & nHostName)
End If
If vLine Like "DNS Suffix*" Then
Dim anSuffixes() As String = vLine.Split(":")
NICListInfo.Items.Add("DNS Suffixes: " & anSuffixes(1))
End If
If (Right(vLine, 2)) Like ("*:") Then
' THis means it is a NIC!
' MsgBox(vLine)
Dim anNic() As String = vLine.Split(":")
mNics.Add() '????
End If
If vLine Like "Media State*" Then
Dim anNic() As String = vLine.Split(":")
mNics(cNics, aNicInfo) = "Media State: " & anNic(1)
' and do WHAT now?
It is for a GUI where it will go into two listboxes - one with a list of Nic Names, the user clicks on the nic and listbox2 shows the relevant info for that Nic Name.