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 enters an IP address like 173.194.36.37
application should display google.com
and vice verse.
Are there any utilities available to perform this operation?
A host, or website, on the Internet is identified by a host name, such as www.example.com . Host names are sometimes called domain names. Host names are mapped to IP addresses, but a host name and an IP address do not have a one-to-one relationship. A host name is used when a web client makes an HTTP request to a host.
DNS servers convert URLs and domain names into IP addresses that computers can understand and use. They translate what a user types into a browser into something the machine can use to find a webpage. This process of translation and lookup is called DNS resolution.
In Java, you can use InetAddress. getLocalHost() to get the Ip Address of the current Server running the Java app and InetAddress. getHostName() to get Hostname of the current Server name.
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);
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With