Java program to Get IP address of the system

Java Programming Java8Java Technologies

The InetAddress class This class represents an Internet Protocol (IP) address. You can get the local IP Address & Hostname of the system using getLocalAddress() method of this class

Example

Live Demo

import java.net.InetAddress;
public class GetIpAddress {
   public static void main(String args[]) throws Exception{
      InetAddress addr = InetAddress.getLocalHost();
      System.out.println("Local HostAddress: "+addr.getHostAddress());
      String hostname = addr.getHostName();
      System.out.println("Local host name: "+hostname);
   }
}

Output

Local HostAddress: 192.168.25.1
Local host name: Tutorialspoint
raja
Published on 25-Apr-2018 17:04:23
Advertisements