List of usage examples for java.net Inet4Address getHostAddress
public String getHostAddress()
From source file:org.commonjava.maven.galley.cache.infinispan.FastLocalCacheProvider.java
private String getCurrentNodeIp() throws SocketException { final Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); Inet4Address top = null; while (nis.hasMoreElements()) { final NetworkInterface ni = nis.nextElement(); final Enumeration<InetAddress> ips = ni.getInetAddresses(); while (ips.hasMoreElements()) { final InetAddress ip = ips.nextElement(); if (ip instanceof Inet4Address && !ip.isLinkLocalAddress()) { if (top == null) { top = (Inet4Address) ip; } else if (!top.isSiteLocalAddress() && ip.isSiteLocalAddress()) { top = (Inet4Address) ip; }/*from ww w. ja v a 2s .co m*/ } } } if (top == null) { throw new IllegalStateException("[galley] IP not found."); } return top.getHostAddress(); }