List of utility methods to do InetAddress Create
InetAddress | getConnectionAddress(InetAddress addr) get Connection Address return addr.isAnyLocalAddress() ? InetAddress.getLoopbackAddress() : addr;
|
InetAddress | getDestinationInetAddress(URI uri) Get an Internet address for a URI destination, resolving the host name if necessary. final String host = uri.getHost(); if (host == null) { return null; final int length = host.length(); if (length == 0) { return null; return InetAddress.getByName(host); |
Collection | getExternalAddresses(InetAddress[] addresses) Returns a collection of all addresses which do not have a local scope (loopbacks etc). ArrayList<InetAddress> result = new ArrayList<InetAddress>(); for (InetAddress addr : addresses) { if (addr.isAnyLocalAddress() || addr.isLinkLocalAddress() || addr.isLoopbackAddress()) continue; result.add(addr); return result; |
String | getFQDN(final InetAddress addr) get FQDN String hostname = addr.getHostName(); if (hostname.indexOf('.') >= 0) { return hostname; hostname = addr.getCanonicalHostName(); if (hostname.indexOf('.') >= 0) { return hostname; String hostAddr = addr.getHostAddress(); try { return InetAddress.getByName(hostAddr).getHostName(); } catch (UnknownHostException e) { return hostAddr; |
int | getFreePort(InetAddress ipAddress) get Free Port int port = getFreeTCPPort(ipAddress); int retry = 20; while (retry > 0) { if (isUDPPortFree(port, ipAddress)) { return port; retry -= 1; return 0; |
int | getFreeSocket(InetAddress bindAddress, int portRangeStart, int portRangeEnd) get Free Socket for (int port = portRangeStart; port < portRangeEnd; port++) { ServerSocket ssocket = null; try { ssocket = new ServerSocket(); ssocket.setReuseAddress(false); ssocket.setSoTimeout(10); ssocket.bind(new InetSocketAddress(bindAddress, port), 10000); return port; ... |
int | getFreeTCPPort(InetAddress ipAddress) get Free TCP Port ServerSocket ss = null; try { ss = new ServerSocket(0); return ss.getLocalPort(); } catch (IOException iOE) { } finally { if (ss != null) { try { ... |
String | getFullHostName(InetAddress netAddress) get Full Host Name if (null == netAddress) { return null; String name = netAddress.getCanonicalHostName(); return name; |
long | getHashFromAddress(final InetAddress address) get Hash From Address return getHashFromIP(address.getAddress());
|
String | getHostAddress(InetAddress address) Get the host address. String host = address.getHostAddress(); if (address instanceof Inet6Address) { if (host.indexOf(':') >= 0 && !host.startsWith("[")) { host = "[" + host + "]"; return host; |