Subversion Repositories javautils

Rev

Go to most recent revision | Details | 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
 
7
// Source: http://www.rgagnon.com/javadetails/java-0452.html
8
// Modified
9
 
10
public class DNSLookup {
11
        public static int doLookup(String hostName, DNSType type)
12
                        throws NamingException {
13
                Hashtable<String, String> env = new Hashtable<String, String>();
14
                env.put("java.naming.factory.initial",
15
                                "com.sun.jndi.dns.DnsContextFactory");
16
                DirContext ictx = new InitialDirContext(env);
17
                Attributes attrs = ictx.getAttributes(hostName, new String[] { type
18
                                .toString() });
19
                Attribute attr = attrs.get(type.toString());
20
                if (attr == null) {
21
                        return 0;
22
                }
23
                return attr.size();
24
        }
25
 
26
        private DNSLookup() {
27
        }
28
}