View Javadoc

1   /*
2    * Copyright 2001-2005 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
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      /***
51       * The default whois host to query.  It is set to whois.internic.net.
52       ***/
53      public static final String DEFAULT_HOST = "whois.internic.net";
54  
55      /***
56       * The default whois port.  It is set to 43 according to RFC 954.
57       ***/
58      public static final int DEFAULT_PORT = 43;
59  
60  
61      /***
62       * The default whois constructor.    Initializes the
63       * default port to <code> DEFAULT_PORT </code>.
64       ***/
65      public WhoisClient()
66      {
67          setDefaultPort(DEFAULT_PORT);
68      }
69  
70      /***
71       * Queries the connected whois server for information regarding
72       * the given handle.  It is up to the programmer to be familiar with the
73       * handle syntax of the whois server.  You must first connect to a whois
74       * server before calling this method, and you should disconnect afterward.
75       * <p>
76       * @param handle  The handle to lookup.
77       * @return The result of the whois query.
78       * @exception IOException  If an I/O error occurs during the operation.
79       ***/
80      public String query(String handle) throws IOException
81      {
82          return query(false, handle);
83      }
84  
85  
86      /***
87       * Queries the connected whois server for information regarding
88       * the given handle and returns the InputStream of the network connection.
89       * It is up to the programmer to be familiar with the handle syntax
90       * of the whois server.  You must first connect to a finger server before
91       * calling this method, and you should disconnect after finishing reading
92       * the stream.
93       * <p>
94       * @param handle  The handle to lookup.
95       * @return The InputStream of the network connection of the whois query.
96       *         Can be read to obtain whois results.
97       * @exception IOException  If an I/O error occurs during the operation.
98       ***/
99      public InputStream getInputStream(String handle) throws IOException
100     {
101         return getInputStream(false, handle);
102     }
103 
104 }
105