Network.Ping Method

Definition

Pings the specified server.

Overloads

Ping(Uri, Int32)

Pings the specified server.

Ping(String, Int32)

Pings the specified server.

Ping(String)

Pings the specified server.

Ping(Uri)

Pings the specified server.

Ping(Uri, Int32)

Source:
Network.vb
Source:
Network.vb
Source:
Network.vb

Pings the specified server.

C#
public bool Ping(Uri address, int timeout);

Parameters

address
Uri

The URI of the server to ping.

timeout
Int32

Time threshold in milliseconds for contacting the destination. Default is 500.

Returns

True if the operation was successful; otherwise False.

Exceptions

No network connection is available.

URL was not valid.

Examples

This example reports whether or not the server can be pinged by determining whether the Ping method returns True.

VB
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.

VB
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.

Remarks

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://".

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 5, 6, 7, 8, 9, 10

Ping(String, Int32)

Source:
Network.vb
Source:
Network.vb
Source:
Network.vb

Pings the specified server.

C#
public bool Ping(string hostNameOrAddress, int timeout);

Parameters

hostNameOrAddress
String

The URL, computer name, or IP number of the server to ping.

timeout
Int32

Time threshold in milliseconds for contacting the destination. Default is 500.

Returns

True if the operation was successful; otherwise False.

Exceptions

No network connection is available.

URL was not valid.

Examples

This example reports whether or not the server can be pinged by determining whether the Ping method returns True.

VB
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.

VB
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.

Remarks

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://".

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 5, 6, 7, 8, 9, 10

Ping(String)

Source:
Network.vb
Source:
Network.vb
Source:
Network.vb

Pings the specified server.

C#
public bool Ping(string hostNameOrAddress);

Parameters

hostNameOrAddress
String

The URL, computer name, or IP number of the server to ping.

Returns

True if the operation was successful; otherwise False.

Exceptions

No network connection is available.

URL was not valid.

Examples

This example reports whether or not the server can be pinged by determining whether the Ping method returns True.

VB
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.

VB
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.

Remarks

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://".

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 5, 6, 7, 8, 9, 10

Ping(Uri)

Source:
Network.vb
Source:
Network.vb
Source:
Network.vb

Pings the specified server.

C#
public bool Ping(Uri address);

Parameters

address
Uri

The URI of the server to ping.

Returns

True if the operation was successful; otherwise False.

Exceptions

No network connection is available.

URL was not valid.

Examples

This example reports whether or not the server can be pinged by determining whether the Ping method returns True.

VB
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.

VB
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.

Remarks

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://".

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 5, 6, 7, 8, 9, 10