How to Get localhost IP Address in Java

Using the, We can Get the localhost IP Address in Java. To get the localhost IP, We can Use the Code like
public class IPAddress {
	public static void main(String[] args) {
	  try {
		InetAddress ip = InetAddress.getLocalHost();
		System.out.println("IP is : " + ip.getHostAddress());
	  } catch (UnknownHostException ex) {
IP is :

localhost ip

The traditional IP Addresses (IPv4) uses a 32-bit number to represent an IP address, and it defines both network and host address. Due to IPv4 addresses running out, a new version of the IP protocol (IPv6) has been invented to offer virtually limitless number of unique addresses. An IP address is written in “dotted decimal” notation, which is 4 sets of numbers separated by period each set representing 8-bit number ranging from (0-255). An example of IPv4 address is

Leave a Comment