Get hostname, when IP address is known

Discussion in 'Java' started by vi, Sep 19, 2005.

  1. vi

    vi Guest

    I have the following program

    import java.net.*;
    public class Inet1 {
    public static void main(String[] a) throws Exception {
    InetAddress i1 = InetAddress.getByName("www.sun.com");
    System.out.println(i1.getHostAddress()); //209.249.116.195
    InetAddress i2 = InetAddress.getByName("209.249.116.195");
    System.out.println(i2.getHostName());
    }
    }

    On the last println statement, I want the hostname to be printed i.e.
    www.sun.com.
    Given a hostname, I am able to get IP address. But, given an IP
    address, I am not able to get the hostname.
    Please suggest a solution.
    Thanks.
     
    vi, Sep 19, 2005
    #1
    1. Advertising

  2. vi

    Oliver Wong Guest

    "vi" <> wrote in message
    news:...
    >I have the following program
    >
    > import java.net.*;
    > public class Inet1 {
    > public static void main(String[] a) throws Exception {
    > InetAddress i1 = InetAddress.getByName("www.sun.com");
    > System.out.println(i1.getHostAddress()); //209.249.116.195
    > InetAddress i2 = InetAddress.getByName("209.249.116.195");
    > System.out.println(i2.getHostName());
    > }
    > }
    >
    > On the last println statement, I want the hostname to be printed i.e.
    > www.sun.com.
    > Given a hostname, I am able to get IP address. But, given an IP
    > address, I am not able to get the hostname.
    > Please suggest a solution.
    > Thanks.


    See RFC953: http://www.faqs.org/rfcs/rfc953.html

    - Oliver
     
    Oliver Wong, Sep 19, 2005
    #2
    1. Advertising

  3. vi

    Eric K Idema Guest

    vi <> wrote:
    > I have the following program


    > import java.net.*;
    > public class Inet1 {
    > public static void main(String[] a) throws Exception {
    > InetAddress i1 = InetAddress.getByName("www.sun.com");
    > System.out.println(i1.getHostAddress()); //209.249.116.195
    > InetAddress i2 = InetAddress.getByName("209.249.116.195");
    > System.out.println(i2.getHostName());
    > }
    > }


    > On the last println statement, I want the hostname to be printed i.e.
    > www.sun.com.
    > Given a hostname, I am able to get IP address. But, given an IP
    > address, I am not able to get the hostname.


    There's nothing wrong with your code. It looks like Sun's nameserver
    isn't configured properly for reverse lookups. Try a few more examples
    and you'll find that some work and some don't. My experience is that
    many companies don't get reverse dns right.

    Eric
     
    Eric K Idema, Sep 19, 2005
    #3
  4. vi

    Roedy Green Guest

    On 19 Sep 2005 09:15:03 -0700, "vi" <> wrote or
    quoted :

    >Given a hostname, I am able to get IP address. But, given an IP
    >address, I am not able to get the hostname.

    see http://mindprod.com/jgloss/ip.html for the whois source code.

    It does not work unless you have a reverse DNS lookup. Some sites will
    not support that. You can try out the code

    java WhoIs mindprod.com
    java WhoIs 24.85.32.136

    Note that sometimes several domains share and IP and vice versa.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 19, 2005
    #4
  5. vi

    Roedy Green Guest

    On Mon, 19 Sep 2005 19:15:22 GMT, Eric K Idema
    <> wrote or quoted :

    > It looks like Sun's nameserver
    >isn't configured properly for reverse lookups.


    that is correct. You can go DNS->IP but not the reverse with Sun. Part
    of the catch is reverse lookup can be used for spam harvesting, and
    other annoying purposes.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 19, 2005
    #5
  6. vi

    Roedy Green Guest

    On 19 Sep 2005 09:15:03 -0700, "vi" <> wrote or
    quoted :

    >On the last println statement, I want the hostname to be printed i.e.
    >www.sun.com.


    to get the info manually see http://mindprod.com/jgloss/whois.html

    In those cases you are looking in private databases.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 19, 2005
    #6
    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. AWieminer
    Replies:
    0
    Views:
    753
    AWieminer
    Jul 12, 2005
  2. Laszlo Nagy
    Replies:
    2
    Views:
    602
    Laszlo Nagy
    Jul 31, 2006
  3. Microlong®
    Replies:
    3
    Views:
    183
    Evertjan.
    Oct 12, 2005
  4. Victor Reyes
    Replies:
    1
    Views:
    109
    MonkeeSage
    Dec 27, 2007
  5. Replies:
    19
    Views:
    523
    Dan Katorza
    Sep 20, 2012
Loading...

Share This Page