Java Host Name Get getLocalShortHostName()

Here you can find the source of getLocalShortHostName()

Description

get Local Short Host Name

License

Open Source License

Declaration

public static String getLocalShortHostName() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;

public class Main {
    private static String cachedShortHostName = null;

    public static String getLocalShortHostName() {
        if (cachedShortHostName != null) {
            return cachedShortHostName;
        }//from ww  w.j a va2s.  c  o  m

        try {
            String hostName;
            InetAddress iAddress = InetAddress.getLocalHost();
            hostName = iAddress.getHostName();
            //            String canonicalHostName = iAddress.getCanonicalHostName();
            String[] parts = hostName.split("\\.");
            hostName = parts[0];
            cachedShortHostName = hostName;
            return cachedShortHostName;
        } catch (Exception e) {
            return e.getMessage();
        }
    }
}

Related

  1. getHostNameByNic()
  2. getHtmlSource(final String host)
  3. getInetHost()
  4. getLedgerAllocatorPoolName(int serverRegionId, int shardId, boolean useHostname)
  5. getLocalCanonicalHostName()
  6. getLogHost()
  7. getMachineHostname()
  8. getMyHostname()
  9. getProxy(String host, String proxyType)