Java Utililty Methods Local Host Get

List of utility methods to do Local Host Get

Description

The list of methods to do Local Host Get are organized into topic(s).

Method

StringgetLocalHostAddress()
Returns the real IP Address of the NIC for the localhost.
try {
    return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
    throw new RuntimeException(e);
StringgetLocalHostAddress()
Gets the set localhost address as URL string (ipv6 addresses are enclosed in [])
byte[] addr = localhost.getAddress();
String localHostAddress = localhost.getHostAddress().replaceAll("%10", "");
if (addr.length == 16) {
    localHostAddress = "[" + localHostAddress + "]";
return localHostAddress;
StringgetLocalhostAddress()
get Localhost Address
String localhostAdress = null;
try {
    final InetAddress localHost = InetAddress.getLocalHost();
    if (localHost != null) {
        localhostAdress = localHost.getHostAddress();
} catch (UnknownHostException ex) {
return localhostAdress;
byte[]getLocalHostID()

Generates an array of 6-bytes that is a fairly reliable identifier of the system on which this code is running.

try {
    Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
    byte[] candidateAddress = null;
    for (; netInterfaces.hasMoreElements();) {
        candidateAddress = netInterfaces.nextElement().getHardwareAddress();
        if (!suspiciousHardwareAddress(candidateAddress))
            break;
        else
...
InetAddressgetLocalHostLANAddress()
get Local Host LAN Address
try {
    InetAddress candidateAddress = null;
    for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements();) {
        NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
        for (Enumeration inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
            InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
            if (!inetAddr.isLoopbackAddress()) {
                if (inetAddr.isSiteLocalAddress()) {
...
StringgetLocalHostName()
get Local Host Name
if (host_ == null) {
    host_ = getLocalAddress().getCanonicalHostName();
return host_;
StringgetLocalHostName()
get Local Host Name
if (localHostName == null) {
    init();
return localHostName;
StringgetLocalHostName()
Get local host name.
String sLocalHostName;
try {
    sLocalHostName = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
    sLocalHostName = "127.0.0.1";
return sLocalHostName;
StringgetLocalHostName()
best effort method to determine host name of localhost.
try {
    final String name = InetAddress.getLocalHost().getCanonicalHostName();
    if (name == null || name.length() == 0) {
        return "localhost";
    } else if (name.equals(InetAddress.getLocalHost().getHostAddress())) {
        return "localhost";
    } else {
        return name;
...
StringgetLocalHostName()
Get this computer's name.
try {
    java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost();
    return localMachine.getHostName();
} catch (java.net.UnknownHostException uhe) {
    System.out.println(uhe.toString());
    return "";