Vinoth
Vinoth

Reputation: 21

ICMP Disable/Blocked:How To Check Internet Connection Using C#

If ICMP Is Blocked/Disabled by Administrator. Is there any way to check the internet connection through C# when ping test is not possible.

Thanks in Advance.

Upvotes: 0

Views: 1161

Answers (1)

Honnes
Honnes

Reputation: 320

I have not tried it yet, but I think the following works.

HttpWebRequest req;
HttpWebResponse resp;

req = (HttpWebRequest)WebRequest.Create("http://www.stackoverflow.com");
resp = (HttpWebResponse)req.GetResponse();

if(resp.StatusCode.ToString().Equals("OK"))
{
      Console.WriteLine("its connected.");
}
else
{
      Console.WriteLine("its not connected.");
}

I think this will do the job, and it might be required to add 'System.Net' or so to the usings.

Upvotes: 0

Related Questions