Web Analytics
Get Hostname from IP Address in Java -->

Get Hostname from IP Address in Java

Learn how to get Hostname from an IP address provided by the user, with Java. Parse the IP address and retrieve the hostname using InetAddress class.

This section provides an example of parsing the Hostname from an IP Address provided by the user using Java.

Also, Get IP Address from Hostname in Java

The following program requires the java.net package for the provision of a Networking Class- InetAddress class. The InetAddress class is used to represent an IP address and perform DNS lookups. 

The InetAddress class cannot be instantiated using its constructors. The static methods of the InetAddress class are invoked directly by referencing the class name, without the reference of an object created using a constructor. 

Some of the available methods are used in the process of getting the hostname from an IP address. In the following implementation, the user provides the IP address.

The methods in the InetAddress class that are used in the following implementation are as follows:

public static InetAddress getByName(String host) throws UnknownHostException

  • Returns an object of type InetAddress class.
  • The object contains LocalHost IP and name.

public String getHostName()

  • Returns the hostname of the IPAddress as a String type data. 

Parsing Hostname for a given IP Address
Parsing Hostname for a given IP Address


You may like these posts

  1. To insert a code use <i rel="pre">code_here</i>
  2. To insert a quote use <b rel="quote">your_qoute</b>
  3. To insert a picture use <i rel="image">url_image_here</i>