How to get the device public IP address in android.
please find my code here. i am getting device ip address. but how i can get the public ip address.
Please help me
import java.util.Enumeration;
public class GetDeviceIp
{
public GetDeviceIp() {}
public static String getIpAddress()
{
try {
Enumeration<java.net.NetworkInterface> en =
java.net.NetworkInterface.getNetworkInterfaces();
Enumeration<java.net.InetAddress> enumIpAddr;
for (; en.hasMoreElements(); enumIpAddr.hasMoreElements())
{
java.net.NetworkInterface intf = (java.net.NetworkInterface)en.nextElement();
enumIpAddr = intf.getInetAddresses();continue;
java.net.InetAddress inetAddress = (java.net.InetAddress)enumIpAddr.nextElement();
if ((!inetAddress.isLoopbackAddress()) &&
((inetAddress instanceof java.net.Inet4Address))) {
return inetAddress.getHostAddress();
}
}
}
catch (java.net.SocketException ex) {
ex.printStackTrace();
return null;
}
}
}