Subversion Repositories javautils

Rev

Rev 4 | Blame | Last modification | View Log | RSS feed

  1. package com.dominicsayers.isemail;
  2.  
  3. import java.util.Hashtable;
  4. import javax.naming.*;
  5. import javax.naming.directory.*;
  6.  
  7. /**
  8.  * This class performs DNS lookups.
  9.  *
  10.  * @author Rgagnon.com and Daniel Marschall
  11.  * @see Source: http://www.rgagnon.com/javadetails/java-0452.html (Modified)
  12.  * @version 2010-06-14
  13.  */
  14. public class DNSLookup {
  15.         public static int doLookup(String hostName, DNSType type)
  16.                         throws NamingException {
  17.                 Hashtable<String, String> env = new Hashtable<String, String>();
  18.                 env.put("java.naming.factory.initial",
  19.                                 "com.sun.jndi.dns.DnsContextFactory");
  20.                 DirContext ictx = new InitialDirContext(env);
  21.                 Attributes attrs = ictx.getAttributes(hostName, new String[] { type
  22.                                 .toString() });
  23.                 Attribute attr = attrs.get(type.toString());
  24.                 if (attr == null) {
  25.                         return 0;
  26.                 }
  27.                 return attr.size();
  28.         }
  29.  
  30.         private DNSLookup() {
  31.         }
  32. }