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();
    }
}