Java Utililty Methods Host Name Get

List of utility methods to do Host Name Get

Description

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

Method

StringgetHostName()
returns the lowercase hostname
if (myHostname == null) {
    try {
        InetAddress addr = InetAddress.getLocalHost();
        myHostname = addr.getHostName().toLowerCase();
    } catch (Exception e) {
        myHostname = "ADDRESS_UNKNOWN";
return myHostname;
StringgetHostname()
get Hostname
try {
    return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
    return "localhost";
StringgetHostName()
get Host Name
try {
    InetAddress addr = InetAddress.getLocalHost();
    String hostName = addr.getHostName();
    if (hostName == null) {
        return "unknownHost";
    int locFirstPeriod = hostName.indexOf('.');
    if (locFirstPeriod > 0) { 
...
StringgetHostname()

Determines the current host's fully qualified hostname.

try {
    InetAddress ia = InetAddress.getLocalHost();
    return ia.getHostName();
} catch (UnknownHostException e) {
    return null;
StringgetHostName()
get Host Name
String result = null;
InetAddress inetAddress = null;
try {
    inetAddress = InetAddress.getLocalHost();
    result = inetAddress.getHostName();
} catch (Exception ex) {
    result = "localhost";
return result;
StringgetHostname()
get the hostname by resolving our own address this method is not async due to possible dns call, we run this with executeBlocking
try {
    InetAddress ip = InetAddress.getLocalHost();
    return ip.getCanonicalHostName();
} catch (UnknownHostException e) {
    return "localhost";
StringgetHostname()
returns the hostname of the machine that Dynamo is running on
try {
    InetAddress address = InetAddress.getLocalHost();
    return address.getHostName();
} catch (UnknownHostException uhe) {
return "unknown";
StringgetHostName()
get Host Name
try {
    return InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
    return null;
StringgetHostname()
get Hostname
String hostName;
final InetAddress localHost;
try {
    localHost = InetAddress.getLocalHost();
    hostName = localHost.getHostName();
} catch (UnknownHostException ignore) {
    hostName = "localhost";
return hostName;
StringgetHostName()
get Host Name
String hostname = System.getenv("HOSTNAME");
if (hostname != null) {
    return hostname;
} else {
    try {
        hostname = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        e.printStackTrace();
...