Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Get hostname, when IP address is known

Reply
Thread Tools

Get hostname, when IP address is known

 
 
vi
Guest
Posts: n/a
 
      09-19-2005
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.

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      09-19-2005

"vi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>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


 
Reply With Quote
 
 
 
 
Eric K Idema
Guest
Posts: n/a
 
      09-19-2005
vi <(E-Mail Removed)> 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

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-19-2005
On 19 Sep 2005 09:15:03 -0700, "vi" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-19-2005
On Mon, 19 Sep 2005 19:15:22 GMT, Eric K Idema
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-19-2005
On 19 Sep 2005 09:15:03 -0700, "vi" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the velocity in real-time when acceleration is known? iherage Java 16 04-20-2006 12:24 AM
Need script to download file at known address Radioactive Man Python 8 09-17-2004 12:05 PM
known Java frame, how to get handle to a edit control box? lucy Java 7 08-20-2004 06:41 AM
RE: How to get decimal form of largest known prime? Tim Peters Python 12 06-17-2004 03:11 AM
How to get decimal form of largest known prime? Daniel Yoo Python 11 06-12-2004 11:59 AM



Advertisments