Code example for InetAddress

Methods: getHostAddresstoString

0
     * TODO: We may introduce a System property or some other method of configuration 
     * TODO: which will specify whether to allow reverse DNS lookup or not 
     */ 
    public static String getHostName(InetAddress address) {
        String result;
        String hostAddress = address.getHostAddress();
        String inetAddr = address.toString();
        int index1 = inetAddr.lastIndexOf('/');
        int index2 = inetAddr.indexOf(hostAddress);
        if (index2 == index1 + 1) {
            if (index1 == 0) {
                result = hostAddress;
            } else { 
                result = inetAddr.substring(0, index1);
            } 
        } else { 
            result = hostAddress;
        } 
        return result;
    } 
Contextual code suggestions in your IDE  Get Codota for Java