Find ip of a url link

by Vinoth 2008-10-24 19:42:54

Hi,
Compile the following code and enter the url name while running you will get ip of that url.


import java.net.*;
import java.io.*;
public class ip {
public static void main ( String[] args ) throws IOException {
String hostname;
BufferedReader input = new BufferedReader ( new InputStreamReader(System.in) );
System.out.print("
");
System.out.print("Host name: ");
hostname = input.readLine();
try {
InetAddress ipaddress = InetAddress.getByName(hostname);
System.out.println("IP address: " + ipaddress.getHostAddress());
//System.out.println("Your IP Address is:"+InetAddress.getLocalHost());
// System.out.println("Host Name of above IP:"+InetAddress.getAddress());
}
catch ( UnknownHostException e ){
System.out.println("Could not find IP address for: " + hostname);
}
}
}

Tagged in:

2313
like
0
dislike
0
mail
flag

You must LOGIN to add comments