Written by Sai Sandeep Thota on July 22, 2013 in Java > Programming

Java Program to get IP Address of a Computer

GET ALERTS:

Get our Latest updates delivered to your mailbox!

This is a small Java program to get the IP Address of a computer. We need to import java.net package and InetAddress class to print system IP Address.

Java program to get IP Address of a Computer

import java.net.InetAddress;
import java.util.*;
import java.lang.*;

class getIP
{
   public static void main(String args[])
   {
	try {
	      System.out.println("Username / IP Address: "+InetAddress.getLocalHost());
	}
	catch (Exception e) {
		System.out.println("Exception occured! "+e.getMessage());	
	}
	
   }
}

Output:

Java Program to get IP Address

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: