public static String getIpAddress(){
try {
Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
while (allNetInterfaces.hasMoreElements()){
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
Enumeration addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()){
ip = (InetAddress) addresses.nextElement();
if (ip != null && ip instanceof Inet4Address && !"127.0.0.1".equals(ip.getHostAddress())){
return ip.getHostAddress();
}
}
}
} catch (Exception e) {
LOGGER.info("",e);
}
return null;
}
try {
Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
while (allNetInterfaces.hasMoreElements()){
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
Enumeration addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()){
ip = (InetAddress) addresses.nextElement();
if (ip != null && ip instanceof Inet4Address && !"127.0.0.1".equals(ip.getHostAddress())){
return ip.getHostAddress();
}
}
}
} catch (Exception e) {
LOGGER.info("",e);
}
return null;
}