You are here

Java program to get IP address

This program prints IP or Internet Protocol address of your computer system. InetAddress class of package is used, getLocalHost method returns InetAddress object which represents local host.

Java programming source code

  1. import;
  3. class IPAddress
  4. {
  5.   public static void main(String args[]) throws Exception
  6.   {
  7.     System.out.println(InetAddress.getLocalHost());
  8.   }
  9. }

Download IP address program class file.

Output of program:
IP address

Output of code prints computer name/ IP address of computer. Java has a very vast Networking API which can be used to develop network applications.