All. I am trying to make a program that I can import a text file of servers into a list view and do a non-stop continuous ping on each of the items in a listview.
The list view gives me multiple columns that I can put data in, server name, Reply status, last timeout, roundtrip time, and current ping total time.
i have already been able to import the servers into the listview with no issues. I want to do a ping on each of the servers in the list view. I figured i need to do a listview.items.count -1 to get the exact number of servers in the item list of column 0.
I already have ping code that works with a single server name. how could i incorporate the below code to do a constant ping and never stop on each server going line by line, pulling the reply of (success or failure) putting the last timeout (current date/time), round trip in milliseconds and current total time of the current ping.
to use the below code I use the below.
I know i need to somehow get the servername out of the listview on column one and code it to cycle through it with an endless loop some how. I will also want to enable the check boxes so I can delete the ones that are selected. I have not clue how to do that. any help is greatly appreciated..
The list view gives me multiple columns that I can put data in, server name, Reply status, last timeout, roundtrip time, and current ping total time.
i have already been able to import the servers into the listview with no issues. I want to do a ping on each of the servers in the list view. I figured i need to do a listview.items.count -1 to get the exact number of servers in the item list of column 0.
I already have ping code that works with a single server name. how could i incorporate the below code to do a constant ping and never stop on each server going line by line, pulling the reply of (success or failure) putting the last timeout (current date/time), round trip in milliseconds and current total time of the current ping.
to use the below code I use the below.
I know i need to somehow get the servername out of the listview on column one and code it to cycle through it with an endless loop some how. I will also want to enable the check boxes so I can delete the ones that are selected. I have not clue how to do that. any help is greatly appreciated..
Code:
PingSystem(txthostname2.Text)
Code:
Sub PingSystem(ByVal HostName As String)
'Ping the system and display results to the txtPingResult control
'Clear any previous ping results
txtpingresults.Text = ""
Dim pingsender As New Ping
Dim options As New PingOptions
'Modify the default fragmentation behavior
options.DontFragment = True
'Create a buffer of 32 bytes of data to be transmitted.
Dim data As String = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
Dim buffer As Byte() = Encoding.ASCII.GetBytes(data)
Dim timeout As Integer = 120
Try
'Attempt ping
Dim reply As PingReply = pingsender.Send(HostName, timeout, buffer, options)
'Ping the target system 4 times to check for consistent results
For i As Integer = 1 To 4
If (reply.Status = IPStatus.Success) Then
txtpingresults.Text += String.Format("Reply from:{1}: Bytes={2} time{3} TTL={4}{0}", _
vbCrLf, reply.Address.ToString, reply.Buffer.Length, GetMs(reply.RoundtripTime), reply.Options.Ttl)
Else
txtpingresults.Text += String.Format("Ping Failed:{1}{0}", vbCrLf, reply.Status.ToString)
End If
Me.Refresh()
'Pause for 1 second before pinging again
System.Threading.Thread.Sleep(1000)
Next
Catch ex As Exception
txtpingresults.Text += String.Format("Ping Failed on host:{1}{0}Error:{2}{0}Detail:{3}{0}", vbCrLf, HostName, ex.Message, ex.InnerException)
End Try
End Sub