Java Host Name Get getHost()

Here you can find the source of getHost()

Description

Gets the hostname of the machine running the code, foregoing the need for exception handling in-line when this information is needed.

License

Open Source License

Return

The hostname of the machine

Declaration

public static String getHost() 

Method Source Code


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

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

public class Main {
    /**/*ww  w.j a  va  2 s. co  m*/
     * Gets the hostname of the machine running the code, foregoing the need for exception handling
     * in-line when this information is needed.
     * 
     * @return The hostname of the machine
     */
    public static String getHost() {
        String host = "unknown";
        try {
            host = InetAddress.getLocalHost().getHostName();
        } catch (final UnknownHostException ex) {
            ex.printStackTrace();
        }
        return host;
    }
}

Related

  1. getDefaultHostName()
  2. getFile(String host, String savePath)
  3. getFullHostname()
  4. getFullyQualifiedDomainName(String unqualifiedHostname)
  5. getFullyQualifiedHostName()
  6. getHost()
  7. getHost(String host)
  8. getHost(String link)
  9. getHost(String s)