V
vi
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.
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.