Java Host Name Get getHostName()

Here you can find the source of getHostName()

Description

get Host Name

License

LGPL

Declaration

public static String getHostName() 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.net.*;

public class Main {
    public static String getHostName() {
        String result = null;//  www .j ava 2 s .  c o m
        InetAddress inetAddress = null;
        try {
            inetAddress = InetAddress.getLocalHost();
            result = inetAddress.getHostName();
        } catch (Exception ex) {
            result = "localhost";
        }
        return result;
    }
}

Related

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