Java program to get IP address

Created with Sketch.

 

Java program to get IP address

Java program to print the IP (Internet Protocol) address of a computer system, we use InetAddress class of java.net package, the getLocalHost method returns InetAddress object, which represents the localhost.

Java IP address program

import java.net.InetAddress;

class IPAddress
{
public static void main(String args[]) throws Exception
{
System.out.println(InetAddress.getLocalHost());
}
}

 

Output of program:
IP address

The output shows the computer name/ IP address of the computer. Java has a very vast Networking API, which can be used to develop network applications.

Leave a Reply

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