Reputation: 2098
I am trying to write code that will return me a domain name if I give it a IP address. Here is what I have done so far;
String destination = "173.194.24.144";
InetAddress address = InetAddress.getByName(destination);
String resolvedHost = address.getHostName();
System.out.println("Translated " + destination + " to host name " + resolvedHost);
What i get is Translated 173.194.24.144 to host name 173.194.24.144
I know for a fact that 173.194.24.144
is an IP address for Google. But with just getting this I tried a little experiment and do a somewhat reverse engineering on the situation. I tried this;
InetAddress addr = InetAddress.getByName("www.google.com");
System.out.println("Host Name " + addr.getHostName());
System.out.println("Host Address " + addr.getHostAddress());
System.out.println("--------------------------------------------");
byte [] add = new byte[]{74, 125, 24, (byte) 105};
InetAddress ip = InetAddress.getByAddress(add);
System.out.println("Host Name " + ip.getHostName());
System.out.println("Host Address " + ip.getHostAddress());
The IP I get in the response is used in the byte array, but the full result I get is;
Host Name www.google.com
Host Address 74.125.24.105
--------------------------------------------
Host Name de-in-f103.1e100.net
Host Address 74.125.24.105
But that just made me more confused as I have got de-in-f103.1e100.net
instead of www.google.com
Can anyone shed any light on this for me?
Upvotes: 2
Views: 124
Reputation: 2098
Upon reading and doing more investigating I was finally able to answer the question. If I add the IP address and domain name to the /etc/hosts
file and run the class again, it will produce the domain name I inserted into the /etc/hosts
file, instead of the original response.
Upvotes: 0
Reputation: 13596
de-in-f103.1e100.net
redirects to Google.
I'm guessing that 74.125.24.105
actually leads to de-in-f103.1e100.net
, which then redirects to Google. In the first one, you created an InetAddress
pointing to google.com
with the same ip. You could get to google by tracing the redirects (tracert
on windows command line).
Upvotes: 1