Java Utililty Methods InetAddress Create

List of utility methods to do InetAddress Create

Description

The list of methods to do InetAddress Create are organized into topic(s).

Method

InetAddressgetConnectionAddress(InetAddress addr)
get Connection Address
return addr.isAnyLocalAddress() ? InetAddress.getLoopbackAddress() : addr;
InetAddressgetDestinationInetAddress(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);
CollectiongetExternalAddresses(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;
StringgetFQDN(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;
intgetFreePort(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;
intgetFreeSocket(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;
...
intgetFreeTCPPort(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 {
...
StringgetFullHostName(InetAddress netAddress)
get Full Host Name
if (null == netAddress) {
    return null;
String name = netAddress.getCanonicalHostName(); 
return name;
longgetHashFromAddress(final InetAddress address)
get Hash From Address
return getHashFromIP(address.getAddress());
StringgetHostAddress(InetAddress address)
Get the host address.
String host = address.getHostAddress();
if (address instanceof Inet6Address) {
    if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
        host = "[" + host + "]";
return host;