Java Local Host Get getLocalHostName()

Here you can find the source of getLocalHostName()

Description

get Local Host Name

License

Apache License

Declaration

public static String getLocalHostName() throws UnknownHostException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    public static String getLocalHostName() throws UnknownHostException {
        try {/* w w w. j  a va  2 s  . c om*/
            return (InetAddress.getLocalHost()).getHostAddress();
        } catch (UnknownHostException uhe) {
            String host = uhe.getMessage();
            if (host != null) {
                int colon = host.indexOf(':');
                if (colon > 0) {
                    return host.substring(0, colon);
                }
            }
            throw uhe;
        }
    }

    public static String getHostAddress() throws UnknownHostException {
        try {
            return (InetAddress.getLocalHost()).getHostAddress();
        } catch (UnknownHostException uhe) {
            String host = uhe.getMessage();
            if (host != null) {
                int colon = host.indexOf(':');
                if (colon > 0) {
                    return host.substring(0, colon);
                }
            }
            throw uhe;
        }
    }
}

Related

  1. getLocalHostName()
  2. getLocalHostName()
  3. getLocalHostName()
  4. GetLocalHostName()
  5. getLocalHostName()
  6. getLocalHostName()
  7. getLocalhostName()
  8. getLocalHostName()
  9. getLocalHostName()