Friend Sub ParseList()
Dim Hostlist(10000, 2) As String
Dim temp, Path As String
Dim CurrentField As String
Dim CurrentRow As String()
Dim X, Y, NumRows, Z As Integer
Dim tcpClient As New System.Net.Sockets.TcpClient()
Dim isConnected, HostAvailable As Boolean
Dim ipaddr As String
With ProgressBar2
.Show()
.Style = ProgressBarStyle.Continuous
.Minimum = 0
.Maximum = 10000
.Value = 0
End With
Path = App_Path()
Using HostReader As FileIO.TextFieldParser = My.Computer.FileSystem.OpenTextFieldParser(Path & "hostlist.txt")
HostReader.SetDelimiters(vbTab)
While Not HostReader.EndOfData
temp = HostReader.ReadFields.ToString
X = X + 1
ProgressBar2.Value = X
System.Windows.Forms.Application.DoEvents()
NumRows = X
End While
End Using
ProgressBar2.Hide()
ReDim Hostlist(X, 2)
X = 0
Y = 0
With ProgressBar2
.Show()
.Style = ProgressBarStyle.Continuous
.Minimum = 0
.Maximum = 10000
.Value = 0
End With
Using HostReader As FileIO.TextFieldParser = My.Computer.FileSystem.OpenTextFieldParser(Path & "hostlist.txt")
HostReader.TextFieldType = FileIO.FieldType.Delimited
HostReader.SetDelimiters(vbTab)
While Not HostReader.EndOfData
CurrentRow = HostReader.ReadFields
For Each CurrentField In CurrentRow
Hostlist(X, Y) = CurrentField
Y += 1
Next
X += 1
Y = 0
ProgressBar2.Value = X
System.Windows.Forms.Application.DoEvents()
End While
End Using
PictureBox2.Show()
ProgressBar2.Value = 0
X = 0
Y = 0
With ProgressBar2
.Show()
.Style = ProgressBarStyle.Continuous
.Minimum = 0
.Maximum = NumRows
.Value = 0
End With
With ProgressBar1
.Show()
.Style = ProgressBarStyle.Continuous
.Minimum = 0
.Maximum = 2
.Value = 0
End With
Label1.Visible = True
Label2.Visible = True
For Z = 1 To NumRows
ProgressBar2.Value = Z
ipaddr = Hostlist(Z, 0)
Label2.Text = "Currently Processing: " & Z.ToString & " of " & NumRows.ToString
System.Windows.Forms.Application.DoEvents()
Try
HostAvailable = My.Computer.Network.Ping(ipaddr, 500)
Catch ex As Exception
End Try
If HostAvailable = True Then
Try
Using tcpClients As New TcpClient
Label1.Text = "Trying: " & ipaddr & " On " & "Port 23"
ProgressBar1.Value = 2
System.Windows.Forms.Application.DoEvents()
tcpClients.Connect(ipaddr, 23)
isConnected = tcpClients.Connected
System.Windows.Forms.Application.DoEvents()
End Using
Catch ex As Exception
Select Case Err.Number
Case 5
isConnected = False
Case Else
MsgBox(Err.Number)
End Select
End Try
Select Case isConnected
Case True
Hostlist(Z, 2) = "Telnet"
ProgressBar1.Value = 0
Case False
ProgressBar1.Value = 2
Try
Using TcpClients As New TcpClient
Label1.Text = "Trying: " & ipaddr & " On " & "Port 22"
ProgressBar1.Value = 2
System.Windows.Forms.Application.DoEvents()
TcpClients.Connect(ipaddr, 22)
isConnected = TcpClients.Connected
System.Windows.Forms.Application.DoEvents()
End Using
Catch ex As Exception
Select Case Err.Number
Case 5
isConnected = False
Case Else
MsgBox(Err.Number)
End Select
End Try
If isConnected = True Then
Hostlist(Z, 2) = "SSH"
isConnected = Nothing
Else : Hostlist(Z, 2) = "ERR"
End If
End Select
End If
'Debug.Print(Z & " " & Hostlist(Z, 0) & " " & Hostlist(Z, 2))
Next
PictureBox3.Show()
System.Windows.Forms.Application.DoEvents()
End Sub