检测网络电缆何时拔出
Windows 知道您何时从 NIC 上拔下网络电缆。有没有一种编程方法可以通过 C++ 中的 API 来确定这一点?
注意:我没有使用 .NET,这是针对封闭 LAN(从未连接到互联网)
Windows knows when you have removed the network cable from your NIC. Is there a programmatic way to determine this via API in C++?
Note: I am not using .NET and this is for a closed LAN (not connected to Internet ever)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Raymond Chen 博客最近发布了类似的内容。以下是相关的文档。我认为 MIB_IPADDR_DISCONNECTED 标志就是您正在寻找的。
Raymond Chen blogged about something similar recently. Here is the relevant documentation. I think the MIB_IPADDR_DISCONNECTED flag is what you are looking for.
将 网络列表管理器 api 与 INetwork 结合使用API。
您可以注册您的应用程序以在网络连接/未连接时接收回调。
或者您可以获取网络列表,然后检查每个网络以查看计算机是否已连接网络。
请记住,Windows 计算机通常会设置多个网络(以太网、wifi 等)。
请记住,仅仅因为网络是已连接,您可能无法访问互联网。例如,您可能有 DNS 或路由问题。或者您可能位于未连接到互联网的工作网络上。
由于上述原因,如果许多诊断工具想真正知道它们是否已连接,它们也会连接到“已知良好”的互联网服务器。像 google.com 这样的网站——他们花了很多钱来确保他们的网站始终正常运行。
最后,您还可能遇到半连接情况,其中数据包正在通过,但不足以真正实现通信流动。要测试这一点,不要只是 ping 一个互联网站点,因为那只是一对数据包。相反,打开 TCP 连接或 ping 以外的其他连接。
Use the Network List Manager api with the INetwork api.
You can register your app to receive callbacks when networks become connected/not connected.
Or you can get the list of networks and then check each of them to see if the machine is network connected or not
Remember that a windows machine will often have multiple networks set up (Ethernet, wifi, etc)
Remember that just because a network is connected, you may not have access to the internet. Eg you could have DNS or routing problems. Or you could be on a working network that is not connected to the internet.
Due to the above, many diagnostic tools also connect to a "known-good" internet server if they want to really know if they're connected or not. Something like google.com -- they spend a lot of money to make sure that their site is up all the time.
Finally, you can also have a semi-connected situation where packets are getting through but not enough to really enable communications to flow. To test this, don't just ping an internet site since that'd only be a pair of packets. Instead, open a TCP connection or something more than a ping.