11

In Windows 7 whenever the internet access gets lost, the network indicator turns yellow. I want to get this status in my software and set an alarm whenever the internet connection gets lost (an internet alarm). How can I get this status? All of the other libraries like this one, just show the status of disconnection (red) and otherwise say that the internet is available. I couldn't find any library that does this nor any API function.

Alireza Noori
  • 14,961
  • 30
  • 95
  • 179

2 Answers2

7

In the Windows API Code Pack there is a NetworkManager class that gets you both IsConnected and IsConnectedToInternet. Comes with some useful samples too. If you want to detect a change in status, do not poll - there are .NET events you can add handlers for just like adding a click handler.

Also see Detect Internet V. local lan connection, An elegant / simple way to check whether internet is available or not, I need a event to detect Internet connect/disconnect, etc.

Community
  • 1
  • 1
Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
  • Awesome answer. The one I was looking for is the Windows API Code Pack. It's exactly what I wanted. – Alireza Noori Jun 01 '11 at 16:11
  • The Windows API Code Pack mysteriously disappeared from Microsoft's site, hence the above link is dead; however the Internet never forgets: http://stackoverflow.com/questions/24081665/windows-api-code-pack-where-is-it – Ian Kemp Mar 04 '17 at 22:23
1

You could modify the network libary you found. Just look at the Network Interface Class. OperationalStatus can be more that up and down :)