演示InetAddress类的使用
import java.io.IOException; import java.net.InetAddress; /**from n o w j a v a . c o m**/ public class Main { public static void main(String[] args) { printAddressDetails("nowjava.com"); // Print the loopback address details printAddressDetails(null); // Print the loopback address details using IPv6 format printAddressDetails("::1"); } public static void printAddressDetails(String host) { System.out.println("Host '" + host + "' details starts..."); try {/*来自 n o w j a v a . c o m*/ InetAddress addr = InetAddress.getByName(host); System.out.println("Host IP Address: " + addr.getHostAddress()); System.out.println("Canonical Host Name: " + addr.getCanonicalHostName()); int timeOutinMillis = 10000; System.out.println("isReachable(): " + addr.isReachable(timeOutinMillis)); System.out.println("isLoopbackAddress(): " + addr.isLoopbackAddress()); } catch (