performing reverse DNS lookup with InetAddress

M

Madhur Ahuja

Hello

I use *InetAddress.getByName("host").getHostName()* to get the host name
from IP Address .
Problem is that this method doesn't do error checking i.e. when a IP address
cannot be resolved, it returns the IP Address in text format rather than the
exception.

Is there any way I can detect whether IP address was successfully resolved
or not.



--
Winners dont do different things, they do things differently.

Madhur Ahuja
India

Homepage : http://madhur.netfirms.com
Email : madhur<underscore>ahuja<at>yahoo<dot>com
 
P

Paul Lutus

Madhur said:
Hello

I use *InetAddress.getByName("host").getHostName()* to get the host name
from IP Address .
Problem is that this method doesn't do error checking i.e. when a IP
address cannot be resolved, it returns the IP Address in text format
rather than the exception.

Is there any way I can detect whether IP address was successfully resolved
or not.

Say again? You just explained how to do it, then asked how to do it. If the
call returns an IP address, not a site name, the address wasn't resolved.

Using:

String s = InetAddress.getByAddress(new byte[] {(byte)64,(byte)226,(byte)42
(byte)135}).getHostName();

If after the call, String s equals a textual IP, the lookup failed:

if (s.matches("\\d+\\.\\d+\\.\\d+\\.\\d+"))
{
System.out.println("Address not resolved.");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top