Detect Internet V. local lan connection

2019-01-26 11:47发布

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?

5条回答
啃猪蹄的小仙女
2楼-- · 2019-01-26 12:11

http://msdn.microsoft.com/en-us/library/aa370750(VS.85).aspx describes the difference between IsConnected and IsConnectedToInternet. Windows 7 only. I don't have a native code sample handy, sorry.

查看更多
你好瞎i
3楼-- · 2019-01-26 12:11

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.

查看更多
Melony?
4楼-- · 2019-01-26 12:27

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.

查看更多
Luminary・发光体
5楼-- · 2019-01-26 12:27

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

查看更多
一夜七次
6楼-- · 2019-01-26 12:28

Pinging 4.2.2.2 is a common means of determining if internet connectivity is present.

The story behind this lies here.

查看更多
登录 后发表回答