Thursday 28 July 2011

A program to find ip address of the website

import java.net.*; //for networking
import java.io.*; //for input/output operations
import java.util.Scanner; // for taking user input

public class ip
{
public static void main( String[] args ) throws IOException
{
Scanner input = new Scanner(System.in); //create object for Scanner Class
System.out.print("Enter your website name: ");
String hostname;
hostname = input.nextLine(); //input from user by reading
//next line in the stream
try
{
InetAddress ipaddress = InetAddress.getByName(hostname);
//InetAddress class gets the ip from website by hostname
System.out.println("ipaddress :" + ipaddress.getHostAddress());
//this method converts it to numbers
}
catch ( UnknownHostException e ) //exception is needed is website is not found
{
System.out.println("Could not find IP address for: " + hostname);
}
}
}

No comments:

Post a Comment