title: check whether Internet connection is available with C#
body: <p>What is the easiest way to check whether internet connection is available programatically?</p>
  
  <p>EDIT:
  As suggested I tried using the following method, but it is always returning true.</p>
  
  <pre><code>[Flags]
  enum InternetConnectionState : int
  {
      INTERNET_CONNECTION_MODEM = 0x1,
      INTERNET_CONNECTION_LAN = 0x2,
      INTERNET_CONNECTION_PROXY = 0x4,
      INTERNET_RAS_INSTALLED = 0x10,
      INTERNET_CONNECTION_OFFLINE = 0x20,
      INTERNET_CONNECTION_CONFIGURED = 0x40
  }
  
  class Program
  {
      [DllImport("WININET", CharSet = CharSet.Auto)]
      static extern bool InternetGetConnectedState(ref InternetConnectionState lpdwFlags, int dwReserved);
  
  static void Main(string[] args)
  {
      InternetConnectionState flags = 0;
      bool isConnected = InternetGetConnectedState(ref flags, 0);
      Console.WriteLine(isConnected);
      //Console.WriteLine(flags);
      Console.ReadKey();
  }
  }
  </code></pre>
  
  <p>Additional Info (if it helps): I access internet over a shared wifi network.</p>