Pings the specified server.
' Usage
Dim value As Boolean = My.Computer.Network.Ping(hostNameOrAddress)
Dim value As Boolean = My.Computer.Network.Ping(address)
Dim value As Boolean = My.Computer.Network.Ping(hostNameOrAddress ,timeout)
Dim value As Boolean = My.Computer.Network.Ping(address ,timeout)
' Declaration
Public Function Ping( _
ByVal hostNameOrAddress As String _
) As Boolean
' -or-
Public Function Ping( _
ByVal address As System.Uri _
) As Boolean
' -or-
Public Function Ping( _
ByVal hostNameOrAddress As String, _
ByVal timeout As Integer _
) As Boolean
' -or-
Public Function Ping( _
ByVal address As System.Uri, _
ByVal timeout As Integer _
) As Boolean
- hostNameOrAddress
String. The URL, computer name, or IP number of the server to ping. Required.
- address
Uri. The URI of the server to ping. Required.
- timeout
Int32. Time threshold in milliseconds for contacting the destination. Default is 500. Required.
Boolean indicating whether or not the operation was successful.
The following conditions may cause an exception to be thrown:
The Ping method is not a fail-safe method for determining the availability of a remote computer: the ping port on the target computer may be turned off or the ping request may be blocked by a firewall or router.
The address passed to the Ping method must be DNS resolvable and cannot be preceded by "http://".
The following table lists examples of tasks involving the My.Computer.Network.Ping method.
This example reports whether or not the server can be pinged by determining whether the Ping method returns True.
If My.Computer.Network.Ping("198.01.01.01") Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
Replace "198.01.01.01" with the IP address, URL, or computer name of the server to ping.
This example reports whether or not the server can be pinged by determining whether the Ping method returned True and specifies a timeout interval of 1000 milliseconds.
If My.Computer.Network.Ping("www.cohowinery.com",1000) Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
Replace "www.cohowinery.com" with the IP address, URL, or computer name of the server to ping.
Namespace: Microsoft.VisualBasic.Devices
Class: Network
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Availability by Project Type
Project type
|
Available
|
|---|
Windows Application
|
Yes
|
Class Library
|
Yes
|
Console Application
|
Yes
|
Windows Control Library
|
Yes
|
Web Control Library
|
Yes
|
Windows Service
|
Yes
|
Web Site
|
Yes
|
The following permissions may be necessary:
For more information, see Code Access Security and Requesting Permissions.
Reference