title: Checking if programm has the internet over wifi
body: <p>After reading some answers and trying to use them I still can not make my code return a correct state, if there is internet over wifi or not. </p>
  
  <p>I must "ping" over WIFI, because we may be connected to the Access Point with no further internet connection. Here is a complete code.</p>
  
  <pre><code>ConnectivityManager CM = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo NI = CM.getActiveNetworkInfo();
  boolean IC = false;             
  IC = CM.requestRouteToHost(ConnectivityManager.TYPE_WIFI, FlavaGr.lookupHost(pingyIp));
  System.out.println("##### IC=" + IC + "  TYPE = " + NI.getTypeName());
  </code></pre>
  
  <p>is here lookupHost, suggested by another user :</p>
  
  <pre><code>public static int lookupHost(String hostname) {
  InetAddress inetAddress;
  try {
      inetAddress = InetAddress.getByName(hostname);
  } catch (UnknownHostException e) {
      return -1;
  }
  byte[] addrBytes;
  int addr;
  addrBytes = inetAddress.getAddress();
  addr = ((addrBytes[3] &amp; 0xff) &lt;&lt; 24)
          | ((addrBytes[2] &amp; 0xff) &lt;&lt; 16)
          | ((addrBytes[1] &amp; 0xff) &lt;&lt; 8)
          |  (addrBytes[0] &amp; 0xff);
  return addr;
  }   
  </code></pre>
  
  <p>IC is always false.
  I feel like the answer is in one step, but still don't know, what to do. </p>
  
  <p>PS Sorry for my English.</p>