C# 網路連線檢查 « 關於網路那些事...
阿新 • • 發佈:2018-12-23
C# 網路連線檢查
C# 可以實作 ping 網路連線檢查
實作方式如下:
class Program { static void Main(string[] args) { //INIT PING OBJECT System.Net.NetworkInformation.Ping objPing = new System.Net.NetworkInformation.Ping(); //設定測試連線及逾時時間 System.Net.NetworkInformation.PingReply PingResult = objPing.Send("www.google.com.tw", 5000); //取得結果 string pingMsg = (PingResult.Status == System.Net.NetworkInformation.IPStatus.Success) ? "連線成功" : "無法連線"; Console.WriteLine(pingMsg); Console.ReadKey(); } }
如果你喜歡我們的文章內容,請在這裡按個讚
Tweet