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
30 public final class fwhois
31 {
32
33 public static void main(final String[] args)
34 {
35 final int index;
36 final String handle;
37 final String host;
38 InetAddress address = null;
39 final WhoisClient whois;
40
41 if (args.length != 1)
42 {
43 System.err.println("usage: fwhois handle[@<server>]");
44 System.exit(1);
45 }
46
47 index = args[0].lastIndexOf('@');
48
49 whois = new WhoisClient();
50
51 whois.setDefaultTimeout(60000);
52
53 if (index == -1)
54 {
55 handle = args[0];
56 host = WhoisClient.DEFAULT_HOST;
57 }
58 else
59 {
60 handle = args[0].substring(0, index);
61 host = args[0].substring(index + 1);
62 }
63
64 try
65 {
66 address = InetAddress.getByName(host);
67 System.out.println("[" + address.getHostName() + "]");
68 }
69 catch (final UnknownHostException e)
70 {
71 System.err.println("Error unknown host: " + e.getMessage());
72 System.exit(1);
73 }
74
75 try
76 {
77 whois.connect(address);
78 System.out.print(whois.query(handle));
79 whois.disconnect();
80 }
81 catch (final IOException e)
82 {
83 System.err.println("Error I/O exception: " + e.getMessage());
84 System.exit(1);
85 }
86 }
87
88 }