Java Host Name Get getShortHostname()

Here you can find the source of getShortHostname()

Description

get Short Hostname

License

Apache License

Return

Hostname of this machine (without the fulld domain info)

Declaration

public static String getShortHostname() 

Method Source Code

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

import java.net.InetAddress;

public class Main {
    /**/*ww w.jav  a 2  s.  co m*/
     * @return Hostname of this machine (without the fulld domain info)
     */
    public static String getShortHostname() {
        return getFullHostname().replaceAll("\\..*", "");
    }

    /**
     * @return Full hostname of this machine.
     */
    public static String getFullHostname() {
        // find the hostname
        String hostname = "unknown";
        try {
            final InetAddress host = InetAddress.getLocalHost();
            hostname = host.getHostName();
        } catch (Exception ignore) {
            // SWALLOWED
        }
        return hostname;
    }
}

Related

  1. getLogHost()
  2. getMachineHostname()
  3. getMyHostname()
  4. getProxy(String host, String proxyType)
  5. getServerHost()
  6. getShortHostName()
  7. getShortHostName()
  8. getShortHostname()
  9. getTimerServerHost()