直接上代码,你们懂得
 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);
            }
        }


本文转载:CSDN博客