blob: a812132b63ca818821824d862e1a39dc50be51fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
/* Listing4601.java */
import java.net.*;
public class Listing4601
{
public static void main(String[] args)
{
if (args.length != 1) {
System.err.println("Usage: java Listing4601 <host>");
System.exit(1);
}
try {
//Get requested address
InetAddress addr = InetAddress.getByName(args[0]);
System.out.println(addr.getHostName());
System.out.println(addr.getHostAddress());
} catch (UnknownHostException e) {
System.err.println(e.toString());
System.exit(1);
}
}
}
|