Java Host Address Get getHostNameOrAddress(String host)

Here you can find the source of getHostNameOrAddress(String host)

Description

get Host Name Or Address

License

Open Source License

Declaration

public static String getHostNameOrAddress(String host) 

Method Source Code


//package com.java2s;
import java.net.*;

public class Main {
    public static String getHostNameOrAddress(String host) {
        String hostname = host;//from   w w  w . j  ava2  s.  c o  m

        try {
            InetAddress ia = InetAddress.getByName(host);

            if (ia != null)
                hostname = ia.getHostName();
        } catch (UnknownHostException uhe) {
        }

        return hostname;
    }
}

Related

  1. getHostName(String address)
  2. getHostName(String address)
  3. getHostName(String localAddress)
  4. getHostnameOrAddress()
  5. getHostnameOrAddress()