codescracker


java

Java Program to Get IP Address



« Previous Program Next Program »


Print IP Address

To find/get the IP address in Java Programming, use the method getLocalHost() and display the IP address on the screen as shown in the following program.

Java Programming Code to Get IP Address

Following Java Program get and display the IP Address on the screen:

/* Java Program Example - Get IP Address */
		
import java.net.InetAddress;
 
public class JavaProgram
{
   public static void main(String args[]) throws Exception
   {
   
      // prints the IP address of your Computer
      System.out.println(InetAddress.getLocalHost());
	  
   }
}

When the above Java Program is compile and executed, it will produce the following output:

Java Program to get ip address

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test