Java Host Address Get getHostName(String localAddress)

Here you can find the source of getHostName(String localAddress)

Description

Get the host name of a local address, if available.

License

Mozilla Public License

Parameter

Parameter Description
localAddress the local address

Return

the host name, or another text if not available

Declaration

public static String getHostName(String localAddress) 

Method Source Code

//package com.java2s;
/*/*from  ww w  . j ava2  s . c o m*/
 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
 * and the EPL 1.0 (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 */

import java.net.InetAddress;

public class Main {
    /**
     * Get the host name of a local address, if available.
     *
     * @param localAddress the local address
     * @return the host name, or another text if not available
     */
    public static String getHostName(String localAddress) {
        try {
            InetAddress addr = InetAddress.getByName(localAddress);
            return addr.getHostName();
        } catch (Exception e) {
            return "unknown";
        }
    }
}

Related

  1. getHostAddressFromProperty(final String property)
  2. getHostExternalAddr()
  3. getHostName(String addr)
  4. getHostName(String address)
  5. getHostName(String address)
  6. getHostnameOrAddress()
  7. getHostnameOrAddress()
  8. getHostNameOrAddress(String host)