title: How to programmatically find the external IP address of a device without using external host?
body: <p>When I read the IP address of the device I always get the local IP address.</p>
  
  <p>I use the following code snippet to do that.</p>
  
  <pre><code>public String getIpAddress() {
     try {
           for (Enumeration&lt;NetworkInterface&gt; en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                  NetworkInterface intf = en.nextElement();
               for (Enumeration&lt;InetAddress&gt; enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                      InetAddress inetAddress = enumIpAddr.nextElement();
                      if (!inetAddress.isLoopbackAddress()) {
                          String ip = Formatter.formatIpAddress(inetAddress.hashCode());
                          Log.d("VPNConnected",ip);
                          return ip;
                      }
                  }
              }
  
          } catch (Exception ex) {
              Log.d("exception", ex.toString());
          }
          return "EMPTY";
      }
  </code></pre>
  
  <p>But I need to read the external IP address without using any external host or web apis such as <a href="http://jsonip.com" rel="noreferrer">http://jsonip.com</a></p>