How to get the ip address in java ?

This tutorial explains how to get ip address in java using java program.In java we have a class called InetAddress which extends object class and implements serializable interface.The instance of InetAddress contains ipadress and its host name.

Java example program to get ip address :

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IpAddressDemo {

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

}

 

Leave a Reply

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