dwb
dwb

Reputation: 483

Detect ping times

I currently have a method to see if a device is 'online' or 'offline'. I am now trying to see if there is a way to see if it is in the middle (by ping times exceeding 300~ or something similar).

Current working code I am using for online/offline

If My.Computer.Network.Ping(RouterBox.Text) Then
        'Online
        RouterPingIcon.Image = My.Resources.PingUP
    Else
        RouterPingIcon.Image = My.Resources.PingDOWN
        'Offline
    End If

Any ideas?

Upvotes: 0

Views: 728

Answers (1)

Drarig29
Drarig29

Reputation: 2245

I found this code (source) :

Public Function GetPingMs(address As String) As Long
    Dim ping As New System.Net.NetworkInformation.Ping
    Return ping.Send(address).RoundtripTime
End Function

Try searching before asking a question...

For example :

If My.Computer.Network.Ping(RouterBox.Text) Then
    'Online
    If GetPingMs(RouterBox.Text) < 300 Then
        'Good ping
        RouterPingIcon.Image = My.Resources.PingUP
    Else
        'Bad ping
        RouterPingIcon.Image = My.Resources.PingMIDDLE
    End If
Else
    RouterPingIcon.Image = My.Resources.PingDOWN
    'Offline
End If

Upvotes: 1

Related Questions