Subversion Repositories javautils

Rev

Rev 4 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 daniel-mar 1
package com.dominicsayers.isemail;
2
 
3
import java.util.Hashtable;
4
import javax.naming.*;
5
import javax.naming.directory.*;
6
 
13 daniel-mar 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
 */
4 daniel-mar 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
}