Get Windows 7's network status

主宰稳场 提交于 2019-12-20 12:31:51

问题


In Windows 7 whenever the internet access gets lost, the network indicator turns yellow. I want to get this status in my software and set an alarm whenever the internet connection gets lost (an internet alarm). How can I get this status? All of the other libraries like this one, just show the status of disconnection (red) and otherwise say that the internet is available. I couldn't find any library that does this nor any API function.


回答1:


In the Windows API Code Pack there is a NetworkManager class that gets you both IsConnected and IsConnectedToInternet. Comes with some useful samples too. If you want to detect a change in status, do not poll - there are .NET events you can add handlers for just like adding a click handler.

Also see Detect Internet V. local lan connection, An elegant / simple way to check whether internet is available or not, I need a event to detect Internet connect/disconnect, etc.




回答2:


You could modify the network libary you found. Just look at the Network Interface Class. OperationalStatus can be more that up and down :)



来源:https://stackoverflow.com/questions/6197954/get-windows-7s-network-status

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!