Wednesday 14 January 2015

Check Internet Connection using .net or c#



Check internet Connectivity
            textBox1.Text = IsConnectedInternet();

          //Process p= Process.Start("cmd","ping www.google.com");
        }
        private string IsConnectedInternet()
        {
         
            string msg = String.Empty;
            try
            {
                Ping p = new Ping();
                p.SendAsync("wwww.google.com", 1000, new byte[32], new PingOptions());
                msg = "Internet is Connected....";
            }

            catch (Exception me)
            {
                msg = "Internet is not Connected.";
            }

            return msg;
       
        }

//second method
using System.Net.NetworkInformation;
...
public bool IsConnectedToInternet()
        {            string host = http://www.c-sharpcorner.com;            bool result = false;            Ping p = new Ping();            try            {                PingReply reply = p.Send(host, 3000);                if (reply.Status == IPStatus.Success)                    return true;            }            catch { }            return result;        }

1 comment: