Home Java Java-get-example Java Get IP Address

Related Tutorials


 
 

Share on Google+Share on Google+

Java Get IP Address

Advertisement
An IP address is either a 32-bit or 128-bit unsigned number used by the internet protocol. To store the host name resolutions, the class InetAddress is used.

Java Get IP Address

     

This section illustrates you how to obtain the IP Address of local host.

An IP address is either a 32-bit or 128-bit unsigned number used by the internet protocol. To store the host name resolutions, the class InetAddress is used. The method getLocalHost() returns the local host and the method getHostAddress() returns the IP address.

 

 

Here is the code of Java Get IP Address Example

import java.net.*;
import java.io.*;

public class GetIPAddress {
public static void main(String [] args) {
try {
InetAddress thisIp =InetAddress.getLocalHost();
System.out.println("IP:"+thisIp.getHostAddress());
}
catch(Exception e) {
e.printStackTrace();
}
}
}

Output will be displayed as:

Download Source Code

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: October 15, 2008

Related Tutorials

Discuss: Java Get IP Address   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:11
yoginder bagga
February 1, 2012
java

thanks .. it works.
Meena
January 11, 2013
ip address

Hoe will i get ip address of a system in a textbox?
rheamay sanchez
February 6, 2012
oop

..HOOO,GRAVEH HRAP..
Marcelo Oliveiros
February 24, 2012
Thanks Man!

Thanks for save me!
Pankaj
June 29, 2012
Query

Please explain me the meaning of these two lines: catch(Exception e) { e.printStackTrace(); } how they function?
Lovely Lalit Singh
July 31, 2012
Related to Java Project

Wanna need some of the projects in java for finding the Derivation and Integration
Lovely Lalit Singh
July 31, 2012
Related to Java Projects for 3rd Year Dimploma

Wanna Some of the Java code for finding the Derivation and Integration of a given Input through the user
sweta
October 8, 2012
Output displayed is wrong IP

IP of my system is 192.15.20.55 where as the output displayed is IP of my system is := 127.0.1.1
Edilsom
November 23, 2012
Don't work online

Try this online and you can't get the Local IP
DMCA.com