Sunday, August 7, 2011

Determine the IP address of a website

You can use Java to determine the IP address of any website.

import java.net.InetAddress;
import java.net.UnknownHostException;

public class GetIPAddress {
public static void main(String[] args) {

// "google.com", "yahoo.com", "hotmail.com" etc.
String hostName = "google.com";
try {
InetAddress in = InetAddress.getByName(hostName);
System.out.println("The IP Address of site is:"
+ in.getHostAddress());
} catch (UnknownHostException e) {
System.out.println(" Invalid Host name or server is down");
}
}
}

Output
The IP Address of site is:74.125.236.81

1 comment: