Export (0) Print
Expand All

How to: Determine if a Remote Computer is Available in Visual Basic

You can use the My.Computer.Network.Ping Method to determine whether a remote computer or host is available. The server can be specified by URL, computer name, or IP address. Do not include http:// when specifying a URL.

The Ping method is not a fail-safe method for determining the availability of a remote computer: the ping port on the target machine may be turned off, or the ping request may be blocked by a firewall or router.

NoteNote:

  The options available in dialog boxes, and the names and locations of menu commands you see, might differ from what is described in Help, depending on your active settings or edition. This Help page was written with General Development Settings in mind. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To ping a server

  • Determine whether the Ping method returns True. This example reports whether or not the server can be pinged, by determining whether the Ping method returned True. Replace 198.01.01.01 with the IP address, URL, or computer name of the server to ping

    If My.Computer.Network.Ping("198.01.01.01") Then
      MsgBox("Server pinged successfully.")
    Else
      MsgBox("Ping request timed out.")
    End If
    

To ping a server and specify a time-out

  • Determine whether the Ping method returns True, specifying the time-out interval in milliseconds. If no time-out is specified, 500 is used as the default. This example reports whether or not the server can be pinged, by determining whether the Ping method returned True, and it specifies a time-out interval of 1000 milliseconds. Replace www.cohowinery.com with the IP address, URL, or computer name of the server to ping.

    If My.Computer.Network.Ping("www.cohowinery.com", 1000) Then
      MsgBox("Server pinged successfully.")
    Else
      MsgBox("Ping request timed out.")
    End If
    

Community Additions

ADD
Show:
© 2014 Microsoft