views:

141

answers:

4

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?

A: 

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.

Martin Beckett
Just because the computer has a private IP address (which also include 10.x.x.x and 172.16-31.x.x) doesn't mean it's not connected to the Internet. As anyone accessing this site from behind a home router performing NAT can attest!
Stephen C. Steel
It wasn't clear what the OP was asking ie. direct internet connection vs NAT
Martin Beckett
+1  A: 

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

The story behind this lies here.

Adam Robinson
Interesting. What's vnsc-bak.sys.gtei.net?
sbi
Although now 8.8.8.8 is probably better (behold the might of google)
Martin Beckett
@Martin: Yes, though 4.2.2.2 is now muscle memory for me. I don't know if I can bear to learn 8.8.8.8 and its uncomfortable angle between index- and middle finger.
Adam Robinson
+2  A: 

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.

Kate Gregory
Thanks, this is exactly the type of thing I am looking for.
MattR
A: 

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.

Eakraly