Refine search
protected String localHostnameImpl() throws UnknownHostException { return InetAddress.getLocalHost().getCanonicalHostName(); }
private String getCanonicalHostname(String hostname) { String canonicalHostname = hostname; try { InetAddress in = InetAddress.getByName(hostname); canonicalHostname = in.getCanonicalHostName(); log.debug("Resolved hostname={} to canonicalHostname={}", hostname, canonicalHostname); } catch (Exception e) { log.warn("Unable to resolve canonical hostname", e); } return canonicalHostname; }
private static String canonicalizeServiceHostName(String hostName) { try { InetAddress address = InetAddress.getByName(hostName); String fullHostName; if ("localhost".equalsIgnoreCase(address.getHostName())) { fullHostName = InetAddress.getLocalHost().getCanonicalHostName(); } else { fullHostName = address.getCanonicalHostName(); } if (fullHostName.equalsIgnoreCase("localhost")) { throw new ClientException("Fully qualified name of localhost should not resolve to 'localhost'. System configuration error?"); } return fullHostName; } catch (UnknownHostException e) { throw new ClientException("Failed to resolve host: " + hostName, e); } }
private static String getLocalCanonicalHostName() { try { return InetAddress.getLocalHost().getCanonicalHostName().toLowerCase(Locale.US); } catch (UnknownHostException e) { throw new UncheckedIOException(e); } } }
/** * Method to get canonical-ized hostname, given a hostname (possibly a CNAME). * This should allow for service-principals to use simplified CNAMEs. * @param hostName The hostname to be canonical-ized. * @return Given a CNAME, the canonical-ized hostname is returned. If not found, the original hostname is returned. */ public static String getCanonicalHostName(String hostName) { try { return InetAddress.getByName(hostName).getCanonicalHostName(); } catch(UnknownHostException exception) { LOG.warn("Could not retrieve canonical hostname for " + hostName, exception); return hostName; } }
private static String canonicalizeServiceHostName(String hostName) { try { InetAddress address = InetAddress.getByName(hostName); String fullHostName; if ("localhost".equalsIgnoreCase(address.getHostName())) { fullHostName = InetAddress.getLocalHost().getCanonicalHostName(); } else { fullHostName = address.getCanonicalHostName(); } if (fullHostName.equalsIgnoreCase("localhost")) { throw new ClientException("Fully qualified name of localhost should not resolve to 'localhost'. System configuration error?"); } return fullHostName; } catch (UnknownHostException e) { throw new ClientException("Failed to resolve host: " + hostName, e); } }
/** * Will return FQDN of the host after doing reverse DNS lookip. * * @return FQDN of host */ public static String getCanonicalHostName() { try { return InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { return LOCALHOST; } }
private static String normalizeHostname(String name) { try { InetAddress address = InetAddress.getByName( "localhost".equalsIgnoreCase(name) ? null : name); return address.getCanonicalHostName(); } catch (UnknownHostException ex) { LOG.warn(MessageFormat.format("Unable to normalize hostname [{0}]", name)); return null; } } /**
/** * Perform a lookup of the host address or FQDN. * @param host the host or null. * @return the address. * @throws IOException if the host name is not valid. * @throws SecurityException if security manager is present and doesn't * allow access to check connect permission. * @since JavaMail 1.5.0 */ private static InetAddress verifyHost(String host) throws IOException { InetAddress a; if (isEmpty(host)) { a = InetAddress.getLocalHost(); } else { a = InetAddress.getByName(host); } if (a.getCanonicalHostName().length() == 0) { throw new UnknownHostException(); } return a; }
public static LeaderLatchListener leaderLatchListenerImpl(final LeaderListenerCallback callback) throws UnknownHostException { final String hostName = InetAddress.getLocalHost().getCanonicalHostName(); return new LeaderLatchListener() { @Override public void isLeader() { callback.leaderCallBack(); LOG.info("{} gained leadership.", hostName); } @Override public void notLeader() { LOG.info("{} lost leadership.", hostName); //Just to be sure callback.notLeaderCallback(); } }; }
/** * Resolves a given hostname by a canonical hostname. When a hostname alias (e.g., those specified * in /etc/hosts) is given, the alias may not be resolvable on other hosts in a cluster unless the * same alias is defined there. In this situation, loadufs would break. * * @param hostname the input hostname, which could be an alias * @return the canonical form of the hostname, or null if it is null or empty * @throws UnknownHostException if the given hostname cannot be resolved */ @Nullable public static String resolveHostName(String hostname) throws UnknownHostException { if (hostname == null || hostname.isEmpty()) { return null; } return InetAddress.getByName(hostname).getCanonicalHostName(); }
/** * Perform a lookup of the host address or FQDN. * @param host the host or null. * @return the address. * @throws IOException if the host name is not valid. * @throws SecurityException if security manager is present and doesn't * allow access to check connect permission. * @since JavaMail 1.5.0 */ private static InetAddress verifyHost(String host) throws IOException { InetAddress a; if (isEmpty(host)) { a = InetAddress.getLocalHost(); } else { a = InetAddress.getByName(host); } if (a.getCanonicalHostName().length() == 0) { throw new UnknownHostException(); } return a; }
public static String hostname() { String hostname = null; try { hostname = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { LOG.error("local_hostname", e); } return hostname; }
/** * Method to get canonical-ized hostname, given a hostname (possibly a CNAME). * This should allow for service-principals to use simplified CNAMEs. * @param hostName The hostname to be canonical-ized. * @return Given a CNAME, the canonical-ized hostname is returned. If not found, the original hostname is returned. */ public String getCanonicalHostName(String hostName) { try { return InetAddress.getByName(hostName).getCanonicalHostName(); } catch(UnknownHostException exception) { LOG.warn("Could not retrieve canonical hostname for " + hostName, exception); return hostName; } }
public static String local_hostname() { String hostname = null; try { hostname = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { LOG.error("local_hostname", e); } return hostname; }
public static String reverseDNSLookupURL(String url) throws UnknownHostException { // Run a reverse DNS lookup on the URL URI uri = URI.create(url); InetAddress address = InetAddress.getByName(uri.getHost()); return uri.getScheme() + "://" + address.getCanonicalHostName() + ":" + uri.getPort(); } }
public static String getHostName() { try { return InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { throw new RuntimeException("Error determining hostname", e); } }
/** * Gets a local host name for the host this JVM is running on. * * @param timeoutMs Timeout in milliseconds to use for checking that a possible local host is * reachable * @return the local host name, which is not based on a loopback ip address */ public static synchronized String getLocalHostName(int timeoutMs) { if (sLocalHost != null) { return sLocalHost; } try { sLocalHost = InetAddress.getByName(getLocalIpAddress(timeoutMs)).getCanonicalHostName(); return sLocalHost; } catch (UnknownHostException e) { throw new RuntimeException(e); } }
private static String getHostName() { try { return InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { logger.log(Level.SEVERE, "Could not get local host name.", e); return "localhost"; } }
/** * Returns canonical host name from which the request is made; used for doAs validation */ private static String getRequestingHost(String requestingUser, HttpServletRequest request) { final String unkHost = "???"; if(request == null) { LOG.warn("request is null; cannot determine hostname"); return unkHost; } try { String address = request.getRemoteAddr();//returns IP addr if(address == null) { LOG.warn(MessageFormat.format("Request remote address is NULL for user [{0}]", requestingUser)); return unkHost; } //Inet4Address/Inet6Address String hostName = InetAddress.getByName(address).getCanonicalHostName(); if(LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Resolved remote hostname: [{0}]", hostName)); } return hostName; } catch (UnknownHostException ex) { LOG.warn(MessageFormat.format("Request remote address could not be resolved, {0}", ex.toString(), ex)); return unkHost; } }