Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Sockets and Internet Protocols
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Sockets and Internet Protocols
DNS Lookup Help
Anant Agarwal
Greenhorn
Posts: 2
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello
Java
Ranchers!
I have written one small Java program to validate a domain name.
Below is the code attached.
import java.util.Hashtable; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttribute; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; public class TestEmail { /** * @param args * @throws NamingException */ public static void main(String[] args) { args = new String[]{"oracle.com"}; if( args.length == 0 ) { System.err.println( "Usage: MXLookup host [...]" ); System.exit( 99 ); } for( int i = 0; i < args.length; i++ ) { try { System.out.println( args[i] + " has " + doLookup( args[i] ) + " mail servers" ); } catch( Exception e ) { System.out.println(args[i] + " : " + e.getMessage()); } } } static int doLookup( String hostName ) throws NamingException { Hashtable env = new Hashtable(); env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); DirContext ictx = new InitialDirContext( env ); Attributes attrs = ictx.getAttributes( hostName, new String[] { "MX","A" }); Attribute attr = attrs.get( "MX" ); if( attr == null ) return( 0 ); return( attr.size() ); } }
Just want to know if this DNS lookup from a java code can be blocked by a firewall or not.
Many Thanks,
Anant
Ulf Dittmer
Rancher
Posts: 43081
77
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Don't use javax.naming for DNS lookups; use
http://www.xbill.org/dnsjava/
Outgoing DNS lookups *can* be blocked, but they generally aren't. All machines must do them periodically, so this would cause more problems than it would solve.
Anant Agarwal
Greenhorn
Posts: 2
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you for your response!
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Email Address Validation
Email domain verificaiton
jndi/dns service provider
Naming Problem
pls help! Error with client in j2ee server
More...