Java Host Name Get getHostname()

Here you can find the source of getHostname()

Description

Get the system's Fully Qualified Domain Name as a string

License

Open Source License

Return

the system's FQDN

Declaration

public static String getHostname() 

Method Source Code

//package com.java2s;

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

import java.util.*;

public class Main {
    /**//from  ww  w  .  j ava 2 s . c  o m
     * Get the system's Fully Qualified Domain Name as a string
     * @return the system's FQDN
     */
    public static String getHostname() {
        String hostname = "";
        try {
            hostname = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException u) {
            StringTokenizer st = new StringTokenizer(u.getMessage());
            while (st.hasMoreTokens())
                hostname = st.nextToken();
        }
        return hostname;
    }
}

Related

  1. getHostname()
  2. getHostName()
  3. getHostname()
  4. getHostName()
  5. getHostName()
  6. getHostname()
  7. getHostName()
  8. getHostName()
  9. getHostname()