pinging server

hapkidoin

New member
Joined
Sep 27, 2013
Messages
4
Location
Pennsylvania, USA
Programming Experience
10+
I have code that does a network ping, as well. This is a tool that one of our guys can use to see if a server is up and if it is experiencing any up/down/up issues. If someone would look at this and tell me what they think, I would really appreciate it. I don't do this particular task very often.

VB.NET:
        Try
            Dim output As System.Net.NetworkInformation.PingReply
            Dim pinger As New System.Net.NetworkInformation.Ping
            output = pinger.Send(TextBox1.Text)
            RichTextBox1.Text += Now.ToString & " - " & output.Status.ToString & Chr(10)
            NumberOfSuccessfulPings += 1
            Label1.Text = "Success: " & NumberOfSuccessfulPings
        Catch ex As Exception
            NumberOfFailedPings += 1
            Label2.Text = "Fail: " & NumberOfFailedPings
            RichTextBox1.Text += ex.Message.ToString
        End Try

I would appreciate the feedback. I have been a programmer for a long time, but I am self-taught as my company had no budget to train me. I've always found a way to do what I needed to do, but I do not know if this is a good (or bad or anything else) way to do it.

Thanks!
 
For a ping, you really don't need all that code...

Dim result As Boolean = My.Computer.Network.Ping(hostNameOrAddress, timeout)


Keep in mind however that this is not completely reliable, as most firewalls will block ICMP by default.
 
I should have put the other part in there. It's on a loop for which the user can set the delay, so most of that code is so it will display multiple results over time. Does that help or do I still have WAY too much in there?
 
Thread split, issue not related thread where is was posted.
 
Back
Top