performing reverse DNS lookup with InetAddress

Discussion in 'Java' started by Madhur Ahuja, Aug 28, 2004.

  1. Madhur Ahuja

    Madhur Ahuja Guest

    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
     
    Madhur Ahuja, Aug 28, 2004
    #1
    1. Advertising

  2. Madhur Ahuja

    Paul Lutus Guest

    Madhur Ahuja wrote:

    >
    > 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.");
    }

    --
    Paul Lutus
    http://www.arachnoid.com
     
    Paul Lutus, Aug 29, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGFuIE5hc2g=?=

    reverse DNS lookup

    =?Utf-8?B?RGFuIE5hc2g=?=, Oct 14, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    473
    =?Utf-8?B?RGFuIE5hc2g=?=
    Oct 14, 2004
  2. Rahul Apte
    Replies:
    0
    Views:
    592
    Rahul Apte
    Apr 27, 2004
  3. Sam Roberts
    Replies:
    0
    Views:
    227
    Sam Roberts
    Mar 20, 2005
  4. ga rg

    Reverse DNS lookup?

    ga rg, Aug 6, 2008, in forum: Ruby
    Replies:
    2
    Views:
    207
    ga rg
    Aug 6, 2008
  5. PHP2
    Replies:
    1
    Views:
    173
    Brian McCauley
    Apr 15, 2004
Loading...

Share This Page