Program to get Host Name and IP address in Java

package programtoprintip;

import java.net.InetAddress;


public class GetIpExample {
	
public static void main(String[] args) throws Exception {
	
    
    	InetAddress inetAddress = InetAddress.getLocalHost();
    	
    	System.out.println("My hostname is : " + inetAddress.getHostName());
        System.out.println("My IP address is  : " + inetAddress);
        
   
	}
}

Output is –

My IP address is : INL-5P5N6C2/10.154.45.64
My hostname is : INL-5P5N6C2