String reverseDNS(InetAddress ipAddress) throws UnknownHostException { String hostName = this.reverseDNSCacheMap.get(ipAddress); if (hostName == null) { String ipAddressString = null; try { ipAddressString = DNS.reverseDns(ipAddress, null); } catch (Exception e) { // We can use InetAddress in case the jndi failed to pull up the reverse DNS entry from the // name service. Also, in case of ipv6, we need to use the InetAddress since resolving // reverse DNS using jndi doesn't work well with ipv6 addresses. ipAddressString = InetAddress.getByName(ipAddress.getHostAddress()).getHostName(); } if (ipAddressString == null) throw new UnknownHostException("No host found for " + ipAddress); hostName = Strings.domainNamePointerToHostName(ipAddressString); this.reverseDNSCacheMap.put(ipAddress, hostName); } return hostName; }
for (InetAddress address : addresses) { try { hosts.add(reverseDns(address, nameserver)); } catch (NamingException ignored) {
private static String reverseDNS(InetAddress ipAddress) throws NamingException, UnknownHostException { String hostName = reverseDNSCacheMap.get(ipAddress); if (hostName == null) { String ipAddressString = null; try { ipAddressString = DNS.reverseDns(ipAddress, null); } catch (Exception e) { // We can use InetAddress in case the jndi failed to pull up the reverse DNS entry // from the name service. Also, in case of ipv6, we need to use the InetAddress // since resolving reverse DNS using jndi doesn't work well with ipv6 addresses. ipAddressString = InetAddress.getByName(ipAddress.getHostAddress()).getHostName(); } if (ipAddressString == null) { throw new UnknownHostException("No host found for " + ipAddress); } hostName = Strings.domainNamePointerToHostName(ipAddressString); reverseDNSCacheMap.put(ipAddress, hostName); } return hostName; }
private String reverseDNS(InetAddress ipAddress) throws NamingException { String hostName = this.reverseDNSCacheMap.get(ipAddress); if (hostName == null) { hostName = Strings.domainNamePointerToHostName(DNS.reverseDns(ipAddress, this.nameServer)); this.reverseDNSCacheMap.put(ipAddress, hostName); } return hostName; }
String reverseDNS(InetAddress ipAddress) throws UnknownHostException { String hostName = this.reverseDNSCacheMap.get(ipAddress); if (hostName == null) { String ipAddressString = null; try { ipAddressString = DNS.reverseDns(ipAddress, null); } catch (Exception e) { // We can use InetAddress in case the jndi failed to pull up the reverse DNS entry from the // name service. Also, in case of ipv6, we need to use the InetAddress since resolving // reverse DNS using jndi doesn't work well with ipv6 addresses. ipAddressString = InetAddress.getByName(ipAddress.getHostAddress()).getHostName(); } if (ipAddressString == null) throw new UnknownHostException("No host found for " + ipAddress); hostName = Strings.domainNamePointerToHostName(ipAddressString); this.reverseDNSCacheMap.put(ipAddress, hostName); } return hostName; }
String reverseDNS(InetAddress ipAddress) throws UnknownHostException { String hostName = this.reverseDNSCacheMap.get(ipAddress); if (hostName == null) { String ipAddressString = null; try { ipAddressString = DNS.reverseDns(ipAddress, null); } catch (Exception e) { // We can use InetAddress in case the jndi failed to pull up the reverse DNS entry from the // name service. Also, in case of ipv6, we need to use the InetAddress since resolving // reverse DNS using jndi doesn't work well with ipv6 addresses. ipAddressString = InetAddress.getByName(ipAddress.getHostAddress()).getHostName(); } if (ipAddressString == null) throw new UnknownHostException("No host found for " + ipAddress); hostName = Strings.domainNamePointerToHostName(ipAddressString); this.reverseDNSCacheMap.put(ipAddress, hostName); } return hostName; }
/** * TestCase: get our local address and reverse look it up * @throws Exception if that fails */ public void testRDNS() throws Exception { InetAddress localhost = getLocalIPAddr(); try { String s = DNS.reverseDns(localhost, null); LOG.info("Local revers DNS hostname is " + s); } catch (NameNotFoundException e) { if (!localhost.isLinkLocalAddress() || localhost.isLoopbackAddress()) { //these addresses probably won't work with rDNS anyway, unless someone //has unusual entries in their DNS server mapping 1.0.0.127 to localhost LOG.info("Reverse DNS failing as due to incomplete networking", e); LOG.info("Address is " + localhost + " Loopback=" + localhost.isLoopbackAddress() + " Linklocal=" + localhost.isLinkLocalAddress()); } } }
/** * @deprecated mistakenly made public in 0.98.7. scope will change to package-private */ @Deprecated public String reverseDNS(InetAddress ipAddress) throws NamingException, UnknownHostException { String hostName = this.reverseDNSCacheMap.get(ipAddress); if (hostName == null) { String ipAddressString = null; try { ipAddressString = DNS.reverseDns(ipAddress, null); } catch (Exception e) { // We can use InetAddress in case the jndi failed to pull up the reverse DNS entry from the // name service. Also, in case of ipv6, we need to use the InetAddress since resolving // reverse DNS using jndi doesn't work well with ipv6 addresses. ipAddressString = InetAddress.getByName(ipAddress.getHostAddress()).getHostName(); } if (ipAddressString == null) throw new UnknownHostException("No host found for " + ipAddress); hostName = Strings.domainNamePointerToHostName(ipAddressString); this.reverseDNSCacheMap.put(ipAddress, hostName); } return hostName; }
/** * Uses {@link InetAddress} in case of {@link DNS} lookup failure. * * @param ipAddr * the address * @return the reverse address * @throws NamingException * @throws UnknownHostException */ public String reverseDNS(InetAddress ipAddr) throws NamingException, UnknownHostException { String hostName = this.reverseDNSCache.get(ipAddr); if (hostName == null) { String ipAddressString = null; try { ipAddressString = DNS.reverseDns(ipAddr, null); } catch (Exception e) { ipAddressString = InetAddress.getByName(ipAddr.getHostAddress()).getHostName(); } if (ipAddressString == null) throw new UnknownHostException("No host found for " + ipAddr); hostName = Strings.domainNamePointerToHostName(ipAddressString); this.reverseDNSCache.put(ipAddr, hostName); } return hostName; }
/** * Returns all the host names associated by the provided nameserver with the * address bound to the specified network interface * * @param strInterface * The name of the network interface to query (e.g. eth0) * @param nameserver * The DNS host name * @return A string vector of all host names associated with the IPs tied to * the specified interface * @throws UnknownHostException */ public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException { String[] ips = getIPs(strInterface); Vector<String> hosts = new Vector<String>(); for (int ctr = 0; ctr < ips.length; ctr++) try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (Exception e) { } if (hosts.size() == 0) return new String[] { InetAddress.getLocalHost().getCanonicalHostName() }; else return hosts.toArray(new String[] {}); }
/** * Returns all the host names associated by the provided nameserver with the * address bound to the specified network interface * * @param strInterface * The name of the network interface to query (e.g. eth0) * @param nameserver * The DNS host name * @return A string vector of all host names associated with the IPs tied to * the specified interface * @throws UnknownHostException */ public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException { String[] ips = getIPs(strInterface); Vector<String> hosts = new Vector<String>(); for (int ctr = 0; ctr < ips.length; ctr++) try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (Exception e) { } if (hosts.size() == 0) return new String[] { InetAddress.getLocalHost().getCanonicalHostName() }; else return hosts.toArray(new String[] {}); }
for (int ctr = 0; ctr < ips.length; ctr++) { try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (UnknownHostException ignored) {
for (int ctr = 0; ctr < ips.length; ctr++) { try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (UnknownHostException ignored) {
for (int ctr = 0; ctr < ips.length; ctr++) { try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (UnknownHostException ignored) {
for (InetAddress address : addresses) { try { hosts.add(reverseDns(address, nameserver)); } catch (NamingException ignored) {
/** * TestCase: get our local address and reverse look it up */ @Test public void testRDNS() throws Exception { InetAddress localhost = getLocalIPAddr(); try { String s = DNS.reverseDns(localhost, null); LOG.info("Local revers DNS hostname is " + s); } catch (NameNotFoundException e) { if (!localhost.isLinkLocalAddress() || localhost.isLoopbackAddress()) { //these addresses probably won't work with rDNS anyway, unless someone //has unusual entries in their DNS server mapping 1.0.0.127 to localhost LOG.info("Reverse DNS failing as due to incomplete networking", e); LOG.info("Address is " + localhost + " Loopback=" + localhost.isLoopbackAddress() + " Linklocal=" + localhost.isLinkLocalAddress()); } } }
/** * TestCase: get our local address and reverse look it up */ @Test public void testRDNS() throws Exception { InetAddress localhost = getLocalIPAddr(); try { String s = DNS.reverseDns(localhost, null); LOG.info("Local revers DNS hostname is " + s); } catch (NameNotFoundException e) { if (!localhost.isLinkLocalAddress() || localhost.isLoopbackAddress()) { //these addresses probably won't work with rDNS anyway, unless someone //has unusual entries in their DNS server mapping 1.0.0.127 to localhost LOG.info("Reverse DNS failing as due to incomplete networking", e); LOG.info("Address is " + localhost + " Loopback=" + localhost.isLoopbackAddress() + " Linklocal=" + localhost.isLinkLocalAddress()); } } }