Subversion Repositories javautils

Rev

Rev 4 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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