Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Network Find the Host name in reverse of given IP address

Related Tutorials


 
 

Share on Google+Share on Google+

Find the Host name in reverse of given IP address

Advertisement
In this section you will learn to retrieve the information about the local host name using the getHostName() method.

Find the Host name in reverse of given IP address

     

In this section you will learn to retrieve the information about the local host name using the getHostName() method. Here is an example that provides the usage of the getHostName() method in more detail.

Create a class "IPReverse". Call the InetAddress class and create a class object and pass the IP address in InetAddress.getByName() method. Now retrieve the Host name of the IP address what we are pass in getByName() method using the getHostName() method.

Here is the Code of the Example :

IPReverse.java

import java.net.*;

public class IPReverseTest {
  public static void main (String[] args) {
  try {
  InetAddress ia = InetAddress.getByName("192.168.10.105");
  System.out.println(ia.getHostName());
  }
  catch (Exception ex) {
  System.err.println("does not fine hostname");
  }
  }
}

The above example shows the host name of the IP address what ever we pass in the getByName() method. The output of the above example is as under, where the hostname shows as TEST1.

Here is the Output of the Example :

C:\roseindia>javac IPReverseTest.java

C:\roseindia>java IPReverseTest
TEST1

Download of this example.

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 16, 2009

Related Tutorials

Discuss: Find the Host name in reverse of given IP address  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Simin Doddamani
April 14, 2011
Getting Hostname from Ip address

Your code to get host name is not working.. Please suggest what to do. Its displaying IP address itself..
DMCA.com