开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜