In my java application if user enters the IP we need to display the host name, if host name is given then we need to display the IP of the host.
For example if user
In terms of domain name, there are no built in utilities, no. You can get the name of a host (but not the domain name) by using getCanonicalHostName()
on InetAddress - that should work. The best answer here linked to the DNS Java project, which will get you the domain name.
Example code to connect to, and get the host name from, one of Google's servers is given below:
public class GetHostName {
public static void main(String[] args) throws Exception {
InetAddress address = InetAddress.getByAddress(new byte[]{74, 125,(byte) 227, 7});
System.out.println(address.getCanonicalHostName());
}
}
What you're looking for is something called DNS. This project seems to be what you're looking for.
The project SomeKittens referred to you looks like a complete DNS server written in Java, which might be more than you need. Have a look at java.net.InetAddress:
java.net.InetAddress.getByName("example.com").getHostAddress();
If you are coding in Java, try using InetAddress
InetAddress addr = InetAddress.getByName("173.194.36.37");
String host = addr.getHostName();
System.out.println(host);