Java Local Host Get getLocalHostAddress()

Here you can find the source of getLocalHostAddress()

Description

Gets the set localhost address as URL string (ipv6 addresses are enclosed in [])

License

Open Source License

Return

The localhost address

Declaration


public static String getLocalHostAddress() 

Method Source Code

//package com.java2s;

import java.net.InetAddress;

public class Main {
    private static InetAddress localhost = null;

    /**//from  w ww  . ja v a  2 s  . c  o m
     * Gets the set localhost address as URL string (ipv6 addresses are enclosed in [])
     * @return The localhost address
     */

    public static String getLocalHostAddress() {
        byte[] addr = localhost.getAddress();

        String localHostAddress = localhost.getHostAddress().replaceAll("%10", "");
        if (addr.length == 16) {
            // ipv6 address
            localHostAddress = "[" + localHostAddress + "]";
        }
        return localHostAddress;
    }
}

Related

  1. getLocalHost()
  2. getLocalHost()
  3. getLocalHost()
  4. getLocalHost()
  5. getLocalHostAddress()
  6. getLocalhostAddress()
  7. getLocalHostID()
  8. getLocalHostLANAddress()
  9. getLocalHostName()