[VB.NET][C#.NET] 使用 ICMP 來 ping

  • 26639
  • 0
  • C#
  • 2008-11-16

摘要:[VB.NET][C#.NET] 使用 ICMP 來 ping

前幾篇文章有提到用ICMP來Ping一個位置

http://www.dotblogs.com.tw/yc421206/Default.aspx

現在也想要增加一下.NET Ping的用法

法一:

System.Net.NetworkInformation 中的 Ping 類別

詳細內容請查閱http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx

C#

法二:

使用VB2005中的My.Computer.Network.Ping 方法

詳細內容請查閱http://msdn.microsoft.com/zh-tw/library/he5sca5t(VS.80).aspx

Ping方法為多載,如下:

' 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


 

Visual Basic

這個範例藉由判斷 Ping 方法是否傳回 True

 參數
hostNameOrAddress
    String。要 Ping 之伺服器的 URL、電腦名稱或 IP 編號。必要項。
address
    Uri。要 Ping 之伺服器的 URI。必要項。
timeout
    Int32。聯繫目的端的時間臨界值 (以毫秒為單位)。預設值為 500。必要項。

 

 法三:使用WMI

VB2005

 

 法四:使用Win32 API

 

未完............................................................................................................待續

 

 

 

若有謬誤,煩請告知,新手發帖請多包涵


Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET

Image result for microsoft+mvp+logo