C# 中代碼執行 ping 操做

在代碼中能夠經過調用 System.Net.NetworkInformation 命名控件下的 Ping 類的 Send() 方法來實現,代碼以下:web

 
var ping = new System.Net.NetworkInformation.Ping();

var result = ping.Send("www.google.com");

if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
    return;

返回的結果是 PingReply 類型,定義以下:google

 

 

上述代碼中的 result 結果以下:spa

 

 

參考:code

How do you check if a website is online in C#?

相關文章
相關標籤/搜索