检测互联网 V. 本地 LAN 连接
无论如何,是否可以使用 Windows api 来检测 Windows 7 计算机的网络连接是互联网连接还是无法访问互联网的 LAN 连接? Windows 7 和 Vista 在网络图标中指出了这一点(仅限本地与本地和互联网),是否有办法以编程方式获取该信息?
Is there anyway with Windows api to detect whether a Windows 7 computer's network connection is an internet connection or a LAN connection without internet access?
Windows 7 and Vista indicate this in the network icon (Local only v. Local and Internet), is there anyway to grab that information progammatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
http://msdn.microsoft.com/en-us /library/aa370750(VS.85).aspx 描述了
IsConnected
和IsConnectedToInternet
之间的区别。仅限 Windows 7。抱歉,我手边没有本机代码示例。http://msdn.microsoft.com/en-us/library/aa370750(VS.85).aspx describes the difference between
IsConnected
andIsConnectedToInternet
. Windows 7 only. I don't have a native code sample handy, sorry.Ping
4.2.2.2
是确定是否存在互联网连接的常用方法。这背后的故事就在这里。
Pinging
4.2.2.2
is a common means of determining if internet connectivity is present.The story behind this lies here.
并不完美。
您可以通过 IP 地址检测您是否位于 lan 上(假设您的本地 DHCP 分发了 192.168.xx.xx 私有地址之一。)
您可以 ping 一个已知的外部站点来检查该 lan 是否有互联网连接。
Not perfectly.
You could detect if you are on a lan from the IP address (assuming your local DHCP handed out one of the 192.168.xx.xx private addresses.)
YOu could ping a known external site to check if that lan has an internet connection.
Windows 7 在链接建立后 5 秒执行 dns.msftncsi.com 的 DNS 查询。除了检查互联网连接之外,没有任何理由这样做。
Windows 7 performs DNS query for dns.msftncsi.com 5 seconds after link establishment. Do not see any reason to do that except for checking internet connection.
Windows API 代码包将为您完成此操作
http://archive.msdn.microsoft.com/WindowsAPICodePack
其 NetworkListManager 类具有 IsConnected 属性指示您是否有 LAN 连接
以及 IsConnectedToInternet 属性(指示您是否有 Internet 连接)
包下载包含一个网络演示应用程序来演示这一点
The Windows API Code Pack will do this for you
http://archive.msdn.microsoft.com/WindowsAPICodePack
its NetworkListManager Class has an IsConnected property that indicates if you have LAN connection
and an IsConnectedToInternet property that indicates if you have Internet connection
the pack download contains a Network Demo application that demonstrates this