public String getIpAddress() {
try {
String ipv4;
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
if (!inetAddress.isLoopbackAddress()
&& InetAddressUtils
.isIPv4Address(ipv4 = inetAddress
.getHostAddress()))
return ipv4;
}
}
}
} catch (SocketException ex) {
log(ex.toString());
}
return "";
}
try {
String ipv4;
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
if (!inetAddress.isLoopbackAddress()
&& InetAddressUtils
.isIPv4Address(ipv4 = inetAddress
.getHostAddress()))
return ipv4;
}
}
}
} catch (SocketException ex) {
log(ex.toString());
}
return "";
}