Skip to content

Commit

Permalink
0000784: Use the NetworkInterface Java class to get the current ipAdd…
Browse files Browse the repository at this point in the history
…ress of a node. Make 1.5 compatible
  • Loading branch information
chenson42 committed Aug 27, 2012
1 parent 865ac99 commit 0b9d11a
Showing 1 changed file with 5 additions and 8 deletions.
Expand Up @@ -94,16 +94,13 @@ public static String getIpAddress() {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
if (!networkInterface.isLoopback() && networkInterface.isUp()) {
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress inetAddress = inetAddresses.nextElement();
if (!inetAddress.isLoopbackAddress()) {
ipAddress = inetAddress.getHostAddress();
}
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress inetAddress = inetAddresses.nextElement();
if (!inetAddress.isLoopbackAddress()) {
ipAddress = inetAddress.getHostAddress();
}
}

}
} catch (Exception ex) {
log.warn(ex.getMessage(), ex);
Expand Down

0 comments on commit 0b9d11a

Please sign in to comment.