Follow me on Linkedin

Program to find IP address of a computer

/*
Exercise : Ex 1(a)
Title : Program to find IP Address of a computer..
Author :Aslam Jainul
*/

import java.net.*;
import java.io.*;
import java.net.InetAddress.*;
public class EX_1_A_IP
{
public static void main(String args[])
{
try
{
DataInputStream obj= new DataInputStream(System.in);

System.out.println("Enter the IP Address.....");

String user_str = obj.readLine();

System.out.println();
InetAddress ip =InetAddress.getByName(user_str);
if(ip.isReachable(3000))
{

System.out.print(" The given IP address is ACTIVE");
System.out.print(" \n\n");
System.out.print(" Host Name : ");
System.out.print(ip.getHostName());
System.out.print(" \n\n");
System.out.print(" Host Address : ");
System.out.print(ip.getHostAddress());
System.out.print(" \n\n");

}
else
{
System.out.println("The given IP address is INACTIVE");
}
}

catch(Exception E)
{
System.out.print("SOME ERROR OCCURED");
}
}
}

Output :





a