Example usage for java.net InetAddress getCanonicalHostName

List of usage examples for java.net InetAddress getCanonicalHostName

Introduction

In this page you can find the example usage for java.net InetAddress getCanonicalHostName.

Prototype

public String getCanonicalHostName() 

Source Link

Document

Gets the fully qualified domain name for this IP address.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] ipAddr = new byte[] { 127, 0, 0, 1 };
    InetAddress addr = InetAddress.getByAddress(ipAddr);
    String hostnameCanonical = addr.getCanonicalHostName();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InetAddress addr = InetAddress.getByName("127.0.0.1");
    byte[] ipAddr = new byte[] { 127, 0, 0, 1 };
    addr = InetAddress.getByAddress(ipAddr);
    // Get the host name
    String hostname = addr.getHostName();
    // Get canonical host name
    String canonicalhostname = addr.getCanonicalHostName();

}

From source file:Main.java

public static void printAddressDetails(String host) throws Exception {
    System.out.println("Host '" + host + "' details starts...");
    InetAddress addr = InetAddress.getByName(host);
    System.out.println("Host  IP  Address: " + addr.getHostAddress());
    System.out.println("Canonical  Host  Name: " + addr.getCanonicalHostName());

    int timeOutinMillis = 10000;
    System.out.println("isReachable(): " + addr.isReachable(timeOutinMillis));
    System.out.println("isLoopbackAddress(): " + addr.isLoopbackAddress());

}

From source file:dk.netarkivet.common.utils.SystemUtils.java

/**
 * Get the first hostname available for this machine, or "localhost" if none
 * are available.//from  www  . java  2 s  . co  m
 *
 * @return A hostname, as returned by
 * InetAddress.getLocalHost().getCanonicalHostName()()
 */
public static String getLocalHostName() {
    String hostname = LOCALHOST;
    try {
        InetAddress localhost = InetAddress.getLocalHost();
        String localhostName = localhost.getCanonicalHostName();
        String localhostIp = localhost.getHostAddress();
        if (log.isTraceEnabled()) {
            log.trace("[getLocalHostName] Resolved: " + localhostName + " (" + localhostIp + ")");
        }
        return localhostName;
    } catch (UnknownHostException e) {
        // If no interfaces, use default;
        log.warn("Unable to resolve localhostname. Returning the default '" + LOCALHOST + "'");
    }
    return hostname;
}

From source file:com.elasticgrid.model.internal.jibx.Conversion.java

public static String serializeInetAddress(InetAddress address) {
    if (address == null)
        return null;
    return address.getCanonicalHostName();
}

From source file:com.cosmicpush.pub.push.XmppPush.java

public static XmppPush newPush(String recipient, String message, String callbackUrl, String... traits) {

    InetAddress remoteAddress = PushUtils.getLocalHost();
    return new XmppPush(recipient, message, callbackUrl, remoteAddress.getCanonicalHostName(),
            remoteAddress.getHostAddress(), BeanUtils.toMap(traits));
}

From source file:com.cosmicpush.pub.push.XmppPush.java

public static XmppPush newPush(String recipient, String message, String callbackUrl,
        Map<String, String> traits) {

    InetAddress remoteAddress = PushUtils.getLocalHost();
    return new XmppPush(recipient, message, callbackUrl, remoteAddress.getCanonicalHostName(),
            remoteAddress.getHostAddress(), traits);
}

From source file:com.mgmtp.perfload.perfmon.util.PerfMonUtils.java

/**
 * Gets all IP addresses of the localhost.
 * // w  w w .  java2 s.  c  o  m
 * @return an array of {@link InetAddress} objects
 */
public static InetAddress[] getNetworkIPAddresses() throws UnknownHostException {
    InetAddress localhost = InetAddress.getLocalHost();
    return InetAddress.getAllByName(localhost.getCanonicalHostName());
}

From source file:com.netflix.genie.server.util.NetUtil.java

private static String getDCHostName() throws GenieException {
    LOG.debug("called");

    if (dcHostName != null && !dcHostName.isEmpty()) {
        return dcHostName;
    }/*from   w ww.j  a  v  a2  s .co  m*/

    try {
        // gets the local instance hostname
        final InetAddress addr = InetAddress.getLocalHost();
        dcHostName = addr.getCanonicalHostName();
    } catch (final UnknownHostException e) {
        final String msg = "Unable to get the hostname";
        LOG.error(msg, e);
        throw new GenieServerException(msg, e);
    }

    return dcHostName;
}

From source file:com.nridge.core.base.std.Platform.java

/**
 * Convenience method that returns the full qualified domain name of the current machine.
 *
 * @return Fully Qualified Domain Name//from   w  w  w  .ja  v a2  s  .c o  m
 */
public static String getFullyQualifiedDomainName() {
    String hostName;

    try {
        InetAddress inetAddress = InetAddress.getLocalHost();
        hostName = inetAddress.getCanonicalHostName();
    } catch (UnknownHostException e) {
        hostName = "localhost";
    }

    return hostName;
}