DNS { public static String reverseDns(InetAddress hostIp, @Nullable String ns) throws NamingException { String[] parts = hostIp.getHostAddress().split("\\."); String reverseIP = parts[3] + "." + parts[2] + "." + parts[1] + "." + parts[0] + ".in-addr.arpa"; DirContext ictx = new InitialDirContext(); Attributes attribute; try { attribute = ictx.getAttributes("dns: + ((ns == null) ? "" : ns) + "/" + reverseIP, new String[] { "PTR" }); } finally { ictx.close(); } String hostname = attribute.get("PTR").get().toString(); int hostnameLength = hostname.length(); if (hostname.charAt(hostnameLength - 1) == '.') { hostname = hostname.substring(0, hostnameLength - 1); } return hostname; }  static String reverseDns(InetAddress hostIp, @Nullable String ns); static String[] getIPs(String strInterface); static String[] getIPs(String strInterface,
      boolean returnSubinterfaces); static String getDefaultIP(String strInterface); static String[] getHosts(String strInterface,
                                  @Nullable String nameserver,
                                  boolean tryfallbackResolution); static String[] getHosts(String strInterface); static String getDefaultHost(@Nullable String strInterface,
                                      @Nullable String nameserver,
                                      boolean tryfallbackResolution); static String getDefaultHost(@Nullable String strInterface); static String getDefaultHost(@Nullable String strInterface,
                                      @Nullable String nameserver); static List<InetAddress> getIPsAsInetAddressList(String strInterface,
      boolean returnSubinterfaces);  }
@Test public void testRDNS() throws Exception { InetAddress localhost = getLocalIPAddr(); try { String s = DNS.reverseDns(localhost, null); LOG.info("Local reverse DNS hostname is " + s); } catch (NameNotFoundException | CommunicationException e) { if (!localhost.isLinkLocalAddress() || localhost.isLoopbackAddress()) { LOG.info("Reverse DNS failing as due to incomplete networking", e); LOG.info("Address is " + localhost + " Loopback=" + localhost.isLoopbackAddress() + " Linklocal=" + localhost.isLinkLocalAddress()); } } }