01 |
public String getLocalIpAddress() { |
02 |
try { |
03 |
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); |
04 |
en.hasMoreElements();) { |
05 |
NetworkInterface intf = en.nextElement(); |
06 |
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); |
07 |
enumIpAddr.hasMoreElements();) { |
08 |
InetAddress inetAddress = enumIpAddr.nextElement(); |
09 |
if (!inetAddress.isLoopbackAddress()) { |
10 |
return inetAddress.getHostAddress().toString(); |
11 |
} |
12 |
} |
13 |
} |
14 |
} catch (SocketException ex) { |
15 |
Log.e(LOG_TAG, ex.toString()); |
16 |
} |
17 |
return null ; |
18 |
} |