What is the best way to check for Internet connectivity using .NET?

后端 未结 27 2340
感动是毒
感动是毒 2020-11-22 07:41

What is the fastest and most efficient way to check for Internet connectivity in .NET?

27条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 08:27

    Another option is the Network List Manager API which is available for Vista and Windows 7. MSDN article here. In the article is a link to download code samples which allow you to do this:

    AppNetworkListUser nlmUser = new AppNetworkListUser();
    Console.WriteLine("Is the machine connected to internet? " + nlmUser.NLM.IsConnectedToInternet.ToString());
    

    Be sure to add a reference to Network List 1.0 Type Library from the COM tab... which will show up as NETWORKLIST.

提交回复
热议问题