This week's book giveaway is in the Agile forum.
We're giving away four copies of Fixing your Scrum and have Ryan Ripley & Todd Miller on-line!
See this thread for details.
Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

clarification about InetAddress class and its mehods

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am expected to get the domain names of servers that are connected to Internet and keep them in a database.

it has been suggested by some members of this forum to make use of InetAddress class.

so just to test and know how to use InetAddress i wrote the following program
the jdk kit i have is jdk6.0

i need some clarifications about the output of the program.



import java.io.*;
import java.net.*;
import javax.swing.*;

public class Inetdemo {

public static void main(String[] args) {
Inetdemo in=new Inetdemo();

}
public Inetdemo(){
String site_name=JOptionPane.showInputDialog("Enter a site name");// accepts input the site name
try{

InetAddress inet=InetAddress.getByName(site_name);
System.out.println("Host name is "+inet.getHostName()+"\nHost Address is "+inet.getHostAddress()+"\nCanonical host name is "+inet.getCanonicalHostName());
}
catch(UnknownHostException ue){
ue.printStackTrace();
System.out.println("HostERROR!");
}
catch(Exception e){
e.printStackTrace();
System.out.print("Exception");
}
}
}


when the input to the program is

a) google.com the output is
Host name is google.com
Host Address is 64.233.187.99
Canonical host name is jc-in-f99.google.com

b) www.google.com the output is
Host name is www.google.com
Host Address is 216.239.37.99
Canonical host name is va-in-f99.google.com

c) 216.239.37.99 the output is
Host name is va-in-f99.google.com
Host Address is 216.239.37.99
Canonical host name is va-in-f99.google.com


doubt 1)
why is the address value is different when the input is google.com from that of www.google.com?

doubt 2)
what is the difference between getCanonicalHostName() and getHostName() methods?
 
Bartender
Posts: 9625
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


public String getHostName()
Gets the host name for this IP address.

If this InetAddress was created with a host name, this host name will be remembered and returned; otherwise, a reverse name lookup will be performed and the result will be returned based on the system configured name lookup service. If a lookup of the name service is required, call getCanonicalHostName.


java.net.InetAddress
 
reply
    Bookmark Topic Watch Topic
  • New Topic