title: Getting IP address of Android when connected to Cellular Network
body: <p>Is there any Simple Way to get the IP address Of my phone when connected to internet through mobile data Network. For getting WiFi IP address i am using following simple Technique.</p>
  
  <pre><code> WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
  String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
  </code></pre>
  
  <p>Is there any way similar to above to get IP address of mobile data network.</p>
  
  <p>I have used following code but it returns MAC addresses ,IP addresses  of both WiFi and cellular network but i am interested only in Cellular IP Address. </p>
  
  <pre><code>String ipAddress = null;
                      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()) {
                                      ipAddress = inetAddress.getHostAddress().toString();
                                      Log.i("Sarao5",ipAddress);
                                  }
                              }
                          }
                      } catch (SocketException ex) {}
  </code></pre>