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