Java Program to Get the IP address

Write a Java program to get the IP address with an example. In this programming language, InetAddress class has all the necessary Internet Protocol (IP) address information. So, we used the Java getLocalHost method to get the localhost address and the getHostAddress method.

package NumPrograms;

import java.net.InetAddress;

public class IpAddress1 {

	public static void main(String[] args) throws Exception {
		
		InetAddress myIpAdd = InetAddress.getLocalHost();
		
		System.out.println("My IP Address is");
		System.out.println(myIpAdd.getHostAddress());
	}

}

JS Output

Java Program to Get the IP address

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.