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.
Thank开发者_如何学运维s in Advance.
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.
精彩评论