Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ip address to fully qualified domain name

807589Jan 22 2007 — edited Oct 6 2008
Dear friends, I am unable to get the correct fully qualified domain name from IP address. Please help. I have already spent more than a day searching for the solution on these forums and on google. So now only option remaining is help from you friends.

I think I need to explain my set up first.
The machine runs on Solaris8 & is part of corporate intranet. Java version 1.4.2. I am just a developer (cannot touch networking) and here is what I know about its network set up.
The machine has a network alias ("bluesky"). So when I access it thru telnet using VPN, the command line shows "bluesky" at the prompt. There are at least two domain names that lead to this machine. One is bluesky.XXX.com and another is somesubdomain.yyy.com.

I have a piece of existing Java code that produces the IP number of this
machine. I want to convert it to its domain name (either bluesky.xxx.com or the other one).

When I connect by VPN to the network and use nslookup against the IP on my XP laptop, it displays the full domain (somesubdomain.yyy.com). When I do the same thing after I join the intranet directly (not thru VPN), it again shows the full domain, but the different one bluesky.xxx.com.

Some of the code I tried:

Try 1:
String ip = "";//valid IP here
InetAddress ia = InetAddress.getByName(ip);
String hostname1 = ia.getCanonicalHostName();
String hostname2 = ia.getHostName();
When I connect to intranet (without VPN) and run the above code on my laptop, hostname1 and hostname2 both generate "bluesky.xxx.com". This is what I want.
But when I run the code on the remote machine, both strings are only
"bluesky". When I run the code on my laptop after logging into the network using VPN, both produce the second fully qualified domain name. That would also be OK for me if I can get it on remote machine.

Try 2:
I added the following line before the above code (based on forum search).
System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");
The result was same as Try1.

Try 3:
InetAddress[] iaa = InetAddress.getAllByName(ip);
for(int i=0;i<iaa.length;i++){
	System.out.println(iaa.getCanonicalHostName());
System.out.println(iaa[i].getHostName());
}
When ran on laptop, it iterates only once (I expected it to iterate twice) and produces bluesky.xxx.com for both println statements.
On remote machine, it again produces only "bluesky".

It's getting frustating. Please help. Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 3 2008
Added on Jan 22 2007
7 comments
1,312 views