java program to determine IP Address & hostname of Local Computer?


Levels of difficulty: / perform operation:

java program

import java.net.InetAddress;
public class Main {
	public static void main(String[] args) 
	   throws Exception {
		InetAddress addr = InetAddress.getLocalHost();
		System.out.println("Local HostAddress:  "+addr.getHostAddress());
		String hostname = addr.getHostName();
		System.out.println("Local host name: "+hostname);
	}
}


Output

Local HostAddress: 192.168.1.4
Local host name: AnkitSingh





Quantitative Aptitude
Reasoning
Programming
Interview