Java program to find IP Address of localhost

A simple Java Program to find the localhost IP Address of your System.

import java.net.InetAddress;

public class ipAddress {
    public static void main(String args[]) throws Exception
   {
      InetAddress HostIP = InetAddress.getLocalHost();
      System.out.println("Your IP4 Address : "+HostIP);
   }
}

To find you need to import InetAddress package.

Output of the program will be something like this,

Your IP4 Address : agur/192.168.1.104

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top