View Single Post
Old Dec 9th, 2007, 5:07 AM   #1
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 272
Rep Power: 2 Jabo is on a distinguished road
Pinger suggestions?

I've wrote a little program to ping servers and report the results. I'd be interested in ways I could have done it better if you don't mind.
vb Syntax (Toggle Plain Text)
  1. Dim entry(1), line(3) As String
  2. Dim sr As StreamReader = New StreamReader(path)
  3. Dim pingres(3) As String
  4.  
  5. errstring = ""
  6.  
  7. Try
  8. Do While sr.EndOfStream = False
  9. entry = sr.ReadLine.Trim.Split(Chr(9))
  10. Dim Ping As Ping = New Ping
  11. Dim PingReply As PingReply
  12. PingReply = Ping.Send(entry(0), 2000)
  13. tssActivity.Text = "Pinging: " & entry(1) & ": " & entry(0)
  14. tssActivity.Invalidate()
  15. line(0) = entry(1) & ": "
  16. line(1) = entry(0)
  17. If PingReply.Status = IPStatus.Success Then
  18. line(2) = PingReply.RoundtripTime.ToString
  19. Else
  20. line(2) = PingReply.Status.ToString
  21. errstring += line(0).PadRight(20) & line(1).PadRight(20) & "Ping: " & line(2).PadRight(30) & Chr(13) & Chr(10)
  22. End If
  23. line(3) = line(0).PadRight(20) & line(1).PadRight(20) & "Ping: " & line(2).PadRight(30) & Chr(13) & Chr(10)
  24. txtResult.Text += line(3)
  25. Ping.Dispose()
  26. txtResult.Invalidate()
  27. Me.Refresh()
  28. Loop
  29. If Not errstring = "" Then
  30. PrntDoc.Print()
  31. End If
  32. Catch ex As Exception
  33. txtResult.Text += ex.Message & Chr(13) & Chr(10)
  34. End Try
  35. sr.Close()
Jabo is offline   Reply With Quote