6

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?

MattR
  • 279
  • 1
  • 3
  • 12

5 Answers5

3

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
  • 18,808
  • 8
  • 56
  • 85
1

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

The story behind this lies here.

Adam Robinson
  • 182,639
  • 35
  • 285
  • 343
0

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
  • 94,801
  • 28
  • 188
  • 263
  • 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 Apr 20 '10 at 19:20
  • It wasn't clear what the OP was asking ie. direct internet connection vs NAT – Martin Beckett Apr 20 '10 at 21:17
0

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.

Pavel Punsky
  • 197
  • 1
  • 8
0

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

Gary Barrett
  • 1,764
  • 5
  • 21
  • 33
  • the question is tagged C++ meaning native code. The Code Pack (which I love and am partially responsible for) is managed code eg C# – Kate Gregory Feb 20 '13 at 12:47