Hey everyone..Hope I can get a simple answer to this one.
I'm trying to write a basic ping program where the user puts in a list of IP's/websites and selects or sets the number of times to ping each address. I then want it to ping the first item in the list, wait five seconds and then ping the next..so on and so fourth until the amount of times to ping each address has been reached.
My loop seams to be working alright but I can't seam to get it so it will pause between each ping. I've created the loop inside a timer and set to 5 seconds and what is happening now is that every 5 seconds it makes one big swoop through the whole list. I've even tried sticking some other options such as dimming "timer" as interval and then placing a timer = 1000 * 5 in my code but that doesn't seam to place a pause in between each individual ping. Also, as you will notice in my code - I have a label (lblTotalPingsReceived) which should increase by 1 when a successful ping is returned. When this loop makes its big swoop through the entire list it counts that whole swoop as 1 instead of the individual pings..
It kind of seams to me like each individual listbox item needs to be put into an array, but i'm not exactly sure how to do that inside a loop..
Here's my code maybe someone can help..
Private Sub pingTimer_Tick(sender As System.Object, e As System.EventArgs) Handles pingTimer.Tick
Dim pingSender As New Ping()
Dim options As New PingOptions()
Dim roundtriptime As String
Dim x As Integer
Dim timer As Integer
For x = 0 To lstIps.Items.Count - 1
' Use the default Ttl value which is 128,
' but change the fragmentation behavior.
options.DontFragment = True
' Create a buffer of 32 bytes of data to be transmitted.
Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Dim buffer() As Byte = Encoding.ASCII.GetBytes(data)
Dim timeout As Integer = 120
Dim reply As PingReply = pingSender.Send(lstIps.SelectedItem, timeout, buffer, options)
If reply.Status = IPStatus.Success Then
timer = 1000 * 5
roundtriptime = GetMs(reply.RoundtripTime)
txtLog.AppendText("Ping Successful with Roundtrip Time: " & roundtriptime & Now & vbCrLf)
lblTotalPingsReceived.Text = TotalPingsReceived + 1
timer = 1000 * 5
txtLog.AppendText("Ping UnSuccessful at: " & Now & vbCrLf)
lblTotalPingsLost.Text = TotalPingsLost + 1
lblTotalPingsSent.Text = TotalPingsSent + 1
pingNumber = pingNumber - 1
Loop Until pingNumber >= 0
pingTimer.Enabled = False
btnStartPing.Text = "Start"