C#测试网络连接测试

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/pp_fzp/article/details/80415931
直接上代码,你们懂得
 private void checkNetConnect()
        {
            string url = "www.baidu.com";

            string state = "";
            Ping ping = new Ping();
            try
            {
                PingReply reply =ping.Send(url);
                if (reply.Status==IPStatus.Success)
                {
                    this.pictureBox3.Image=Test.Properties.Resources.connected;
                    state = "Netconnect Normal";
                    this.label1.Text = state;
                }
                     if (reply.Status==IPStatus.TimedOut)
                {
                    this.pictureBox3.Image = Test.Properties.Resources.noconnected;
                    state = "Netconnect Abnormal";
                    this.label1.Text = state;
                }
            }
            catch (Exception ex)
            {
                string exceptions = ex.Message.ToString();

                throw new ApplicationException(exceptions);
            }
        }

猜你喜欢

转载自blog.csdn.net/pp_fzp/article/details/80415931