In my app I need to fetch the server ip.. my code to fetch ip is
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
Log.v("","ip1--:" + inetAddress);
Log.v("", "ip2--:" + inetAddress.getHostAddress());
String ipv4;
if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ipv4 = inetAddress.getHostAddress())) {
String ip = inetAddress.getHostAddress().toString();
Toast.makeText(getApplicationContext(), inetAddress., Toast.LENGTH_SHORT).show();
Log.v("","ip---::" + ip);
// return inetAddress.getHostAddress().toString();
return ipv4;
}
}
}
but it is returning the local address if a device is connected to a networked wifi device. Please do tell how I can fetch the parent ip of the network. Thanks in advance...