Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-11-2008, 03:56 PM
Member
 
Join Date: May 2008
Posts: 3
anuta is on a distinguished road
Cnanging the DNS server
Hi

How can I change (from java code) the DNS server used by InetAddress for hosts resolution?

Thanks in advance
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-11-2008, 04:42 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
What do you want to achieve? The DNS server comes from machine configuration.
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-12-2008, 09:00 AM
Member
 
Join Date: May 2008
Posts: 3
anuta is on a distinguished road
In Machine configuration can be defined a list of active DNS servers. Those servers can recognize a different set of domains.
There could be an IP adress that only known by the secondary DNS server and not known by the primary one.

When I am trying to resolve a host
InetAddress.getByName()
it is connected to the first active DNS server on the my machine configuration, and if the host is not recognized not trying to connect to next DNS server on the list.

So that is what I am trying to do, to specify the DNS server for the host resolution.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-13-2008, 09:20 AM
Member
 
Join Date: May 2008
Posts: 3
anuta is on a distinguished road
well no one answers so i figured it out by myself
static public String resolveHostWithAllDnsServers(String ip)
{
List nameservers = sun.net.dns.ResolverConfiguration.open ().nameservers();
for( int i =1; i< nameservers.size() ; i++ )
{
String dnsServer =nameservers.get(i).toString();
try
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
env.put(Context.PROVIDER_URL, "dns://"+dnsServer+"/.");
DirContext ictx = new InitialDirContext(env);
String reversedIp=getReversedIP(ip) ;
Attributes attr = ictx.getAttributes(reversedIp+".in-addr.arpa",new String[]{"PTR"});
Attribute attrib = attr.get("PTR") ;
String host=(String)attrib.get(0);
return host;
}
catch (NamingException e)
{
e.printStackTrace();
}
}
return ip;
}

public static String getReversedIP(String ip)
{
StringTokenizer st = new java.util.StringTokenizer(ip, ".");
String reversedIp=st.nextToken();
while ( st.hasMoreTokens())
{
reversedIp = st.nextToken()+"."+reversedIp;
}
return reversedIp;
}
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-14-2008, 08:50 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
Nicely done . Thanks for posting for others too.
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
One server to another server redirection chaudhuri_abhi Java Servlet 1 02-11-2008 08:05 PM
Web-App server connection - How to hit the particular app server from the web server maruthi_s Enterprise JavaBeans 1 01-06-2008 01:32 PM
SQL server elish11 Database 1 12-14-2007 01:13 PM
123 Web Messenger Server 1.2 JavaBean Java Announcements 0 08-10-2007 05:32 PM
WAS Server Albert Enterprise JavaBeans 1 06-25-2007 06:38 AM


All times are GMT +3. The time now is 04:45 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org