List of usage examples for java.net NetworkInterface isLoopback
public boolean isLoopback() throws SocketException
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public String getHostOrIP() { try {// w ww. j a v a 2 s . c o m InetAddress i = java.net.InetAddress.getLocalHost(); if (i.isLoopbackAddress()) { Enumeration<NetworkInterface> nie = NetworkInterface.getNetworkInterfaces(); while (nie.hasMoreElements()) { NetworkInterface current = nie.nextElement(); if (!current.isLoopback()) { Enumeration<InetAddress> iae = current.getInetAddresses(); while (iae.hasMoreElements()) { InetAddress currentI = iae.nextElement(); if (!currentI.isLoopbackAddress()) { return currentI.getHostAddress(); } } } } } return i.getHostAddress(); } catch (Throwable t) { com.codename1.io.Log.e(t); return null; } }