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()
get Host Name
String host = "unknownhost";
try {
    host = java.net.InetAddress.getLocalHost().getHostName();
} catch (java.net.UnknownHostException e) {
return host;
StringgetHostname()
Get the system's Fully Qualified Domain Name as a string
String hostname = "";
try {
    hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException u) {
    StringTokenizer st = new StringTokenizer(u.getMessage());
    while (st.hasMoreTokens())
        hostname = st.nextToken();
return hostname;
StringgetHostname()
get Hostname
String hostname = null;
try {
    hostname = getHostnameFromInetAddress();
} catch (UnknownHostException unhe) {
    hostname = getHostnameFromCommand();
return hostname;
StringgetHostName()
Returns the hostname of the current host
return InetAddress.getLocalHost().getHostName();
StringgetHostName()
Returns the host name.
try {
    Runtime run = Runtime.getRuntime();
    Process process = run.exec("hostname");
    InputStreamReader isr = new InputStreamReader(process.getInputStream());
    BufferedReader br = new BufferedReader(isr);
    StringBuilder buffer = new StringBuilder();
    String line;
    while ((line = br.readLine()) != null)
...
StringgetHostname()
Determine the hostname of the machine Kettle is running on
String lastHostname = "localhost";
try {
    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    while (en.hasMoreElements()) {
        NetworkInterface nwi = en.nextElement();
        Enumeration<InetAddress> ip = nwi.getInetAddresses();
        while (ip.hasMoreElements()) {
            InetAddress in = (InetAddress) ip.nextElement();
...
StringgetHostName()
get Host Name
return getLocalAddress().getCanonicalHostName();
StringgetHostName()
API to find the hostname.
String hostOS = System.getProperty("os.name");
String hostName = null;
if (hostOS != null && hostOS.indexOf("Win") >= 0) {
    hostName = System.getenv("COMPUTERNAME");
} else { 
    hostName = System.getenv("HOSTNAME");
try {
...
StringgetHostname()
get Hostname
try {
    String result = InetAddress.getLocalHost().getHostName();
    if (result != "")
        return result;
} catch (UnknownHostException e) {
String host = System.getenv("COMPUTERNAME");
if (host != null)
...
StringgetHostName()
get Host Name
try {
    return getLocalHost().getHostName();
} catch (Exception e) {
    return "localhost";