Java Host Name Get getHostname()

Here you can find the source of getHostname()

Description

get Hostname

License

Open Source License

Declaration

public static String getHostname() 

Method Source Code

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

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {
    public static String getHostname() {
        try {/*ww w . jav a 2  s .  c om*/
            String result = InetAddress.getLocalHost().getHostName();
            if (result != "")
                return result;
        } catch (UnknownHostException e) {
        }

        String host = System.getenv("COMPUTERNAME");
        if (host != null)
            return host;

        host = System.getenv("HOSTNAME");
        if (host != null)
            return host;

        return "unknown";
    }
}

Related

  1. getHostName()
  2. getHostName()
  3. getHostname()
  4. getHostName()
  5. getHostName()
  6. getHostName()
  7. getHostname()
  8. getHostName(Proxy proxy)
  9. getHostName(String destination)