Share via


Network.Ping 方法

定義

Ping 指定的伺服器。

多載

Ping(Uri, Int32)

Ping 指定的伺服器。

Ping(String, Int32)

Ping 指定的伺服器。

Ping(String)

Ping 指定的伺服器。

Ping(Uri)

Ping 指定的伺服器。

Ping(Uri, Int32)

Ping 指定的伺服器。

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

參數

address
Uri

要 Ping 之伺服器的 URI。

timeout
Int32

連接目的端的時間臨界值,以毫秒為單位。 預設值是 500。

傳回

如果作業成功,則為 True,否則為 False

例外狀況

沒有可用的網路連線。

URL 無效。

範例

這個範例會藉由判斷方法是否 Ping 傳回 True,來報告是否可以 Ping 伺服器。

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

將取代 "198.01.01.01" 為要 Ping 的伺服器 IP 位址、URL 或電腦名稱。

此範例會藉由判斷 Ping 是否傳 True 回方法,並指定 1000 毫秒的逾時間隔,來報告伺服器是否可以 Ping。

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

將取代 "www.cohowinery.com" 為要 Ping 的伺服器 IP 位址、URL 或電腦名稱。

備註

方法 Ping 不是判斷遠端計算機可用性的失敗安全方法:目標計算機上的 Ping 埠可能會關閉,或防火牆或路由器可能會封鎖 Ping 要求。

傳遞至 方法的 Ping 位址必須是 DNS 可解析,且前面不能加上 「http://」。。

另請參閱

適用於

Ping(String, Int32)

Ping 指定的伺服器。

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

參數

hostNameOrAddress
String

要 Ping 之伺服器的 URL、電腦名稱或 IP 編號。

timeout
Int32

連接目的端的時間臨界值,以毫秒為單位。 預設值是 500。

傳回

如果作業成功,則為 True,否則為 False

例外狀況

沒有可用的網路連線。

URL 無效。

範例

這個範例會藉由判斷方法是否 Ping 傳回 True,來報告是否可以 Ping 伺服器。

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

將取代 "198.01.01.01" 為要 Ping 的伺服器 IP 位址、URL 或電腦名稱。

此範例會藉由判斷 Ping 是否傳 True 回方法,並指定 1000 毫秒的逾時間隔,來報告伺服器是否可以 Ping。

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

將取代 "www.cohowinery.com" 為要 Ping 的伺服器 IP 位址、URL 或電腦名稱。

備註

方法 Ping 不是判斷遠端計算機可用性的失敗安全方法:目標計算機上的 Ping 埠可能會關閉,或防火牆或路由器可能會封鎖 Ping 要求。

傳遞至 方法的 Ping 位址必須是 DNS 可解析,且前面不能加上 「http://」。。

另請參閱

適用於

Ping(String)

Ping 指定的伺服器。

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

參數

hostNameOrAddress
String

要 Ping 之伺服器的 URL、電腦名稱或 IP 編號。

傳回

如果作業成功,則為 True,否則為 False

例外狀況

沒有可用的網路連線。

URL 無效。

範例

這個範例會藉由判斷方法是否 Ping 傳回 True,來報告是否可以 Ping 伺服器。

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

將取代 "198.01.01.01" 為要 Ping 的伺服器 IP 位址、URL 或電腦名稱。

此範例會藉由判斷 Ping 是否傳 True 回方法,並指定 1000 毫秒的逾時間隔,來報告伺服器是否可以 Ping。

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

將取代 "www.cohowinery.com" 為要 Ping 的伺服器 IP 位址、URL 或電腦名稱。

備註

方法 Ping 不是判斷遠端計算機可用性的失敗安全方法:目標計算機上的 Ping 埠可能會關閉,或防火牆或路由器可能會封鎖 Ping 要求。

傳遞至 方法的 Ping 位址必須是 DNS 可解析,且前面不能加上 「http://」。。

另請參閱

適用於

Ping(Uri)

Ping 指定的伺服器。

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

參數

address
Uri

要 Ping 之伺服器的 URI。

傳回

如果作業成功,則為 True,否則為 False

例外狀況

沒有可用的網路連線。

URL 無效。

範例

這個範例會藉由判斷方法是否 Ping 傳回 True,來報告是否可以 Ping 伺服器。

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

將取代 "198.01.01.01" 為要 Ping 的伺服器 IP 位址、URL 或電腦名稱。

此範例會藉由判斷 Ping 是否傳 True 回方法,並指定 1000 毫秒的逾時間隔,來報告伺服器是否可以 Ping。

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

將取代 "www.cohowinery.com" 為要 Ping 的伺服器 IP 位址、URL 或電腦名稱。

備註

方法 Ping 不是判斷遠端計算機可用性的失敗安全方法:目標計算機上的 Ping 埠可能會關閉,或防火牆或路由器可能會封鎖 Ping 要求。

傳遞至 方法的 Ping 位址必須是 DNS 可解析,且前面不能加上 「http://」。。

另請參閱

適用於