I have method to find the DHCP address and host address. how to find the dynamic ip address assigned to my device. I am able get the address from http://www.ip2location.com/default.aspx
how to get this IP in device?
I have method to find the DHCP address and host address. how to find the dynamic ip address assigned to my device. I am able get the address from http://www.ip2location.com/default.aspx
how to get this IP in device?
if you want the external IP this website can help you, they also have an XML API hope this helps. If you need the local IP (if on WIFI) there should be something in the Android api
You could use an external server to request your IP, like @Midday suggests. This is probably the easiest solution. The problem is that you will have to depend on the network and the remote server which might not always be reliable.
You can also get it directly from your device, but you have to jump through hoops to do so – getting your device's IP address isn't as simple as it should be on Android.
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
Notice that the ipAddress
is an integer.
For instance if your IP address is "86.52.119.245":
getIpAddress
will be 4118230102.Hope it helps.