The InetAddress
class encapsulates both the numerical IP address and its domain name.
The following example prints the addresses and names of the local machine and two Internet web sites:
// Demonstrate InetAddress. import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static void main(String args[]) throws UnknownHostException { InetAddress Address = InetAddress.getLocalHost(); System.out.println(Address); Address = InetAddress.getByName("www.google.com"); System.out.println(Address); InetAddress SW[] = InetAddress.getAllByName("www.nba.com"); for (int i = 0; i < SW.length; i++) System.out.println(SW[i]); }/*w w w . jav a2s . co m*/ }