-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostLookup.java
More file actions
47 lines (44 loc) · 1011 Bytes
/
Copy pathHostLookup.java
File metadata and controls
47 lines (44 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package softwareDev;
import java.util.Scanner;
import java.net.InetAddress;
import java.net.UnknownHostException;
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.println("\nEnter a host name: ");
host = sc.nextLine();
try
{
InetAddress[] addresses // array of ip addresses
= InetAddress.getAllByName(host);
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();
if (s.equalsIgnoreCase("Y"))
return true;
else if (s.equalsIgnoreCase("N"))
return false;
}
}
}