Java Host Name Get getHostName()

Here you can find the source of getHostName()

Description

get Host Name

License

Open Source License

Declaration

public static String getHostName() 

Method Source Code


//package com.java2s;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {
    public static String getHostName() {
        InetAddress addr;//from  www  .  j a v a 2 s .  c o m
        try {
            addr = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            return "localhost";
        }
        return addr.getHostName();
    }
}

Related

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