Reputation: 4249
I have written the two program 1st whois.java to find the ip address of the given hostname
import java.net.*;
import java.io.*;
public class whois{
public static void main(String args[]) throws IOException{
String hostName = args[0];
try{
InetAddress ipaddress = InetAddress.getByName(hostName);
System.out.println("IP address: " + ipaddress.getHostAddress());
}catch(UnknownHostException e){
System.out.println("Could not find IP address for: " + hostName);
}
}
}
and other whois2.java which finds hostname for given ip
import java.net.*;
import java.io.*;
class whois2{
public static void main(String args[]){
try{
String str[] = args[0].split("\\.");
byte btArr[] = new byte[]{(byte)Integer.parseInt(str[0]), (byte)Integer.parseInt(str[1]), (byte)Integer.parseInt(str[2]), (byte)Integer.parseInt(str[3])};
InetAddress ipAddr = InetAddress.getByAddress(btArr);
System.out.println("Host name for this is : " + ipAddr.getHostName());
}catch(UnknownHostException e){
System.out.println("Unable to find the host for ip specified " + args[0]);
}
}
}
and then i ran the program with jdk 1.6 and get following outputs:
$java whois google.com
IP address: 209.85.231.104
$java whois2 209.85.231.104
Host name for this is : maa03s01-in-f104.1e100.net
why the host name is different not google.com?
Thanks in advance
Upvotes: 2
Views: 2875
Reputation: 30146
The server responsible, as defined by the DNS lookup, for handling requests to a particular hostname need not have the same hostname as that of the original lookup.
A more typical example would be that requests for foobar.com are handled by a server at an IP, with IP having hostname www.foobar.com.
Note also that the handling server may vary by region.
So I get the same using the linux host tool:
joel@bohr:~$ host google.com
google.com has address 173.194.37.104
... requests to google.com should be handled by the server at 173.194.37.104
joel@bohr:~$ host 173.194.37.104
104.37.194.173.in-addr.arpa domain name pointer lhr14s02-in-f104.1e100.net.
... the hostname of the server at 173.194.37.104 is lhr14s02-in-f104.1e100.net
joel@bohr:~$ host lhr14s02-in-f104.1e100.net
lhr14s02-in-f104.1e100.net has address 173.194.37.104
... and sanity check, the IP of lhr14s02-in-f104.1e100.net is indeed 173.194.37.104
Upvotes: 2
Reputation: 114757
whois(ip)
resolves to the name of the registered server, not to an entry on a domain name server.
Same happens when we use whois services on the web:
http://whois.domaintools.com/google.com resolves to IP 74.125.155.99
(from my location!), http://whois.domaintools.com/74.125.155.99 resolves the host px-in-f99.1e100.net
(which again is different from your results)
Upvotes: 1