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

SetgetAllMyHostAdresses()
get All My Host Adresses
Set<InetAddress> addresses = new HashSet<InetAddress>();
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while (en.hasMoreElements()) {
    Enumeration<InetAddress> ias = en.nextElement().getInetAddresses();
    while (ias.hasMoreElements())
        addresses.add(ias.nextElement());
return addresses;
...
InetAddressgetByName(String host)
get By Name
if (host == null)
    throw new NullPointerException("can't lookup null host");
return InetAddress.getByName(host);
StringgetCanonicalHostName()
get Canonical Host Name
return localhost.getCanonicalHostName();
StringgetCanonicalHostname()
Gets the canonical hostname of this machine.
return InetAddress.getLocalHost().getCanonicalHostName();
StringgetCanonicalHostName()
Will return FQDN of the host after doing reverse DNS lookip.
try {
    return InetAddress.getLocalHost().getCanonicalHostName();
} catch (UnknownHostException e) {
    return LOCALHOST;
StringgetCanonicalHostName()
get Canonical Host Name
String result = new String();
try {
    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    String eth0 = "";
    String wlan0 = "";
    while (en.hasMoreElements()) {
        NetworkInterface intf = en.nextElement();
        Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
...
StringgetCanonicalHostName()
Returns the fully-qualified domain name of the local host in all lower case.
try {
    return getExternalAddressOfLocalSystem().getCanonicalHostName().toLowerCase();
} catch (UnknownHostException e) {
    throw new RuntimeException(e);
StringgetCasServerHostName()
Gets cas server host name.
try {
    final String hostName = InetAddress.getLocalHost().getCanonicalHostName();
    final int index = hostName.indexOf('.');
    if (index > 0) {
        return hostName.substring(0, index);
    return hostName;
} catch (final Exception e) {
...
StringgetCurrentHost()
get Current Host
String hostname = "localhost";
try {
    hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
    e.printStackTrace();
return hostname;
StringgetDefaultHostName()
Returns the default host name.
try {
    return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
String host = System.getenv("COMPUTERNAME"); 
if (host != null) {
    return host;
host = System.getenv("HOSTNAME"); 
if (host != null) {
    return host;
return "";