Java InetAddress Create getHostAddress(InetAddress address)

Here you can find the source of getHostAddress(InetAddress address)

Description

Get the host address.

License

Mozilla Public License

Parameter

Parameter Description
address the address

Return

the host address

Declaration

private static String getHostAddress(InetAddress address) 

Method Source Code

//package com.java2s;
/*//from w ww . jav  a 2  s.c o m
 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
 * and the EPL 1.0 (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 */

import java.net.Inet6Address;
import java.net.InetAddress;

public class Main {
    /**
     * Get the host address. This method adds '[' and ']' if required for
     * Inet6Address that contain a ':'.
     *
     * @param address the address
     * @return the host address
     */
    private static String getHostAddress(InetAddress address) {
        String host = address.getHostAddress();
        if (address instanceof Inet6Address) {
            if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
                host = "[" + host + "]";
            }
        }
        return host;
    }
}

Related

  1. getFreePort(InetAddress ipAddress)
  2. getFreeSocket(InetAddress bindAddress, int portRangeStart, int portRangeEnd)
  3. getFreeTCPPort(InetAddress ipAddress)
  4. getFullHostName(InetAddress netAddress)
  5. getHashFromAddress(final InetAddress address)
  6. getHostAddress(InetAddress anAddress)
  7. getHostAddress(InetAddress host)
  8. getHostName(InetAddress address)
  9. getHostName(InetAddress ia)