Android get IP Address


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public String getLocalIpAddress() {
  2. try {
  3. for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
  4. NetworkInterface intf = en.nextElement();
  5. for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
  6. InetAddress inetAddress = enumIpAddr.nextElement();
  7. if (!inetAddress.isLoopbackAddress()) {
  8. return inetAddress.getHostAddress().toString();
  9. }
  10. }
  11. }
  12. } catch (SocketException ex) {
  13. Log.e(LOG_TAG, ex.toString());
  14. }
  15. return null;
  16. }

URL: http://androidcore.com/android-programming-tutorials/633-how-to-get-the-ip-address-of-your-android-device.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.