1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.net.examples.unix;
19
20 import java.io.IOException;
21 import java.net.InetAddress;
22 import java.net.UnknownHostException;
23
24 import org.apache.commons.net.whois.WhoisClient;
25
26
27
28
29 public final class fwhois {
30
31 public static void main(final String[] args) {
32 final int index;
33 final String handle;
34 final String host;
35 InetAddress address = null;
36 final WhoisClient whois;
37
38 if (args.length != 1) {
39 System.err.println("usage: fwhois handle[@<server>]");
40 System.exit(1);
41 }
42
43 index = args[0].lastIndexOf('@');
44
45 whois = new WhoisClient();
46
47 whois.setDefaultTimeout(60000);
48
49 if (index == -1) {
50 handle = args[0];
51 host = WhoisClient.DEFAULT_HOST;
52 } else {
53 handle = args[0].substring(0, index);
54 host = args[0].substring(index + 1);
55 }
56
57 try {
58 address = InetAddress.getByName(host);
59 System.out.println("[" + address.getHostName() + "]");
60 } catch (final UnknownHostException e) {
61 System.err.println("Error unknown host: " + e.getMessage());
62 System.exit(1);
63 }
64
65 try {
66 whois.connect(address);
67 System.out.print(whois.query(handle));
68 whois.disconnect();
69 } catch (final IOException e) {
70 System.err.println("Error I/O exception: " + e.getMessage());
71 System.exit(1);
72 }
73 }
74
75 }