Home Java Network Find Your Host Name/IP Address



Find Your Host Name/IP Address
Posted on: June 16, 2009 at 12:00 AM
In this section you will learn about the getLocalHost() method to print the Host name as well as the IP Address of the local system.

Find Your Host Name/IP Address

     

In this section you will learn about the getLocalHost() method to print the Host name as well as the IP Address of the local system. For do for the same we have to call InetAddress class then we need to create a object, in which we store the local host information. Then after we use the print command to print the stored value of the InetAddress object local. The example for the above process is as under.

Here is the Code of the Example :

IPaddress.java

import java.net.*;

public class Ipaddress{
  public static void main(String args[]){
  try{
  InetAddress local= InetAddress.getLocalHost();
  System.out.println ("Local IP Address is : " + local);
  }
  catch (UnknownHostException e){
  System.err.println ("Can't detect IP Address : " + e);
  }
  }
}

The output of the above example is as under, In which the host name of the local system is Comp20 and the IP address is 192.168.10.103.

Here is the Output of the Example :

C:\roseindia>javac Ipaddress.java

C:\roseindia>java Ipaddress
Local IP Address is : comp20/192.168.10.103

Download of this example

Related Tags for Find Your Host Name/IP Address:
cclassormformobjectioformataddresscreatelocalforcalladdtohoststoreinformationeinrminfocalasmnetoscaddnetosjadclesalllocmeobjdotorsamewhichseeessathainflleasassamssamthavstatiinforminformatjeono


More Tutorials from this section

Ask Questions?    Discuss: Find Your Host Name/IP Address   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.