I'm trying to get my cell phone ip address by using WifiManager and WifiInfo classes.
It returns correct ip address reversed.
public String getWifiIpAddress() {
WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wi = wm.getConnectionInfo();
byte[] ipAddress = BigInteger.valueOf(wi.getIpAddress()).toByteArray();
try {
InetAddress myAddr = InetAddress.getByAddress(ipAddress);
String hostAddr = myAddr.getHostAddress();
return hostAddr;
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
result : 73.0.168.192