开发者

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

开发者 https://www.devze.com 2023-02-21 13:49 出处:网络
If ICMP Is Blocked/Disabled by Administrator. Is there any way to check the internet connection through C# when ping test is not possible.

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

精彩评论

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