Local Machine IP

/* Get Local IP and Hostname */
import java.io.*;
import java.net.InetAddress;

public class getIP {
	public static void main(String[] argv) throws Exception {
		InetAddress addr = InetAddress.getLocalHost();

		/* Get IP Address */
		System.out.println("IP Address: "+addr.getHostAddress());

		/* Get hostname */
		System.out.println("Hostname: "+addr.getHostName());

/* Output */
IP Address:
Hostname: localhost

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!