Szerkesztés

Megosztás a következőn keresztül:


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)

Pings the specified server.

public:
 bool Ping(Uri ^ address, int timeout);
public bool Ping (Uri address, int timeout);
member this.Ping : Uri * int -> bool
Public Function Ping (address As Uri, timeout As Integer) As Boolean

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.

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.

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

Ping(String, Int32)

Pings the specified server.

public:
 bool Ping(System::String ^ hostNameOrAddress, int timeout);
public bool Ping (string hostNameOrAddress, int timeout);
member this.Ping : string * int -> bool
Public Function Ping (hostNameOrAddress As String, timeout As Integer) As Boolean

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.

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.

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

Ping(String)

Pings the specified server.

public:
 bool Ping(System::String ^ hostNameOrAddress);
public bool Ping (string hostNameOrAddress);
member this.Ping : string -> bool
Public Function Ping (hostNameOrAddress As String) As Boolean

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.

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.

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

Ping(Uri)

Pings the specified server.

public:
 bool Ping(Uri ^ address);
public bool Ping (Uri address);
member this.Ping : Uri -> bool
Public Function Ping (address As Uri) As Boolean

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.

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.

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