01: /*
02: * Copyright 2001-2005 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.net;
17:
18: import java.io.IOException;
19: import java.io.InputStream;
20:
21: /***
22: * The WhoisClient class implements the client side of the Internet Whois
23: * Protocol defined in RFC 954. To query a host you create a
24: * WhoisClient instance, connect to the host, query the host, and finally
25: * disconnect from the host. If the whois service you want to query is on
26: * a non-standard port, connect to the host at that port.
27: * Here's a sample use:
28: * <pre>
29: * WhoisClient whois;
30: *
31: * whois = new WhoisClient();
32: *
33: * try {
34: * whois.connect(WhoisClient.DEFAULT_HOST);
35: * System.out.println(whois.query("foobar"));
36: * whois.disconnect();
37: * } catch(IOException e) {
38: * System.err.println("Error I/O exception: " + e.getMessage());
39: * return;
40: * }
41: * </pre>
42: *
43: * <p>
44: * <p>
45: * @author Daniel F. Savarese
46: ***/
47:
48: public final class WhoisClient extends FingerClient {
49: /***
50: * The default whois host to query. It is set to whois.internic.net.
51: ***/
52: public static final String DEFAULT_HOST = "whois.internic.net";
53:
54: /***
55: * The default whois port. It is set to 43 according to RFC 954.
56: ***/
57: public static final int DEFAULT_PORT = 43;
58:
59: /***
60: * The default whois constructor. Initializes the
61: * default port to <code> DEFAULT_PORT </code>.
62: ***/
63: public WhoisClient() {
64: setDefaultPort(DEFAULT_PORT);
65: }
66:
67: /***
68: * Queries the connected whois server for information regarding
69: * the given handle. It is up to the programmer to be familiar with the
70: * handle syntax of the whois server. You must first connect to a whois
71: * server before calling this method, and you should disconnect afterward.
72: * <p>
73: * @param handle The handle to lookup.
74: * @return The result of the whois query.
75: * @exception IOException If an I/O error occurs during the operation.
76: ***/
77: public String query(String handle) throws IOException {
78: return query(false, handle);
79: }
80:
81: /***
82: * Queries the connected whois server for information regarding
83: * the given handle and returns the InputStream of the network connection.
84: * It is up to the programmer to be familiar with the handle syntax
85: * of the whois server. You must first connect to a finger server before
86: * calling this method, and you should disconnect after finishing reading
87: * the stream.
88: * <p>
89: * @param handle The handle to lookup.
90: * @return The InputStream of the network connection of the whois query.
91: * Can be read to obtain whois results.
92: * @exception IOException If an I/O error occurs during the operation.
93: ***/
94: public InputStream getInputStream(String handle) throws IOException {
95: return getInputStream(false, handle);
96: }
97:
98: }
|