I have created an Android app which uses WebView to load internet pages. I want to get the mobile user IP Address. How to do it??
Asked
Active
Viewed 5,328 times
0
-
you should think of googling your question : http://stackoverflow.com/questions/6064510/how-to-get-ip-address-of-the-device – Guian Mar 08 '13 at 18:23
-
what you want surfing website ip or your device ip??? – QuokMoon Mar 08 '13 at 18:26
-
Thnks @Guian ... dunno how i missed it. – user2129794 Mar 08 '13 at 18:27
-
@altaf I want device IP – user2129794 Mar 08 '13 at 18:27
2 Answers
0
This will load ip address on screen
webview.loadUrl("http://www.whatismyip.com")

DjHacktorReborn
- 2,908
- 2
- 20
- 29
-1
public static String getipAddress() {
try {
for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String ipaddress=inetAddress.getHostAddress().toString();
Log.e("ip address",""+ipaddress);
return ipaddress;
}
}
}
} catch (SocketException ex) {
Log.e("Socket exception in GetIP Address of Utilities", ex.toString());
}
return null;
}
Also add in mainfest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

QuokMoon
- 4,387
- 4
- 26
- 50
-
Am getting casting error at two places: `NetworkInterface intf = **(NetworkInterface)** en.nextElement();` `InetAddress inetAddress = **(InetAddress)** enumIpAddr.nextElement();` – user2129794 Mar 08 '13 at 18:43