主机IP查找应用
import java.net.InetAddress;/**来自 NowJava.com - 时 代 Java**/ import java.net.UnknownHostException; import java.util.Scanner; public class HostLookup { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { System.out.println("Welcome to the IP lookup application."); String host; do { System.out.print("\nEnter a host name: "); host = sc.nextLine(); try { InetAddress[] addresses = InetAddress.getAllByName(host); /* *来 自 时代Java - nowjava.com */ for (InetAddress ip : addresses) System.out.println(ip.toString()); } catch (UnknownHostException e) { System.out.println("Unknown host."); } } while (doAgain()); } private static boolean doAgain() { System.out.println(); String s; while (true) { System.out.print("Look up another? " + "(Y or N) "); s = sc.nextLine();