Home Java Java-get-example Java Get IP Address



Java Get IP Address
Posted on: October 15, 2008 at 12:00 AM
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

Related Tags for Java Get IP Address:
cclassiomethodsedgetinternetiplocalhostnumbernamereturnintaddressetlresolutionprotocollocalunsignedaddbitsolutiontohoststoresignedbiesignituseincalasstamntnetoscaddnetossolutionsadclestoclocmeinternprotorsurnresolutionssoesscolisand128-bitutissthst12eitherprndonolo


More Tutorials from this section

Ask Questions?    Discuss: Java Get 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.