001    /*
002     * Copyright 2001-2005 The Apache Software Foundation
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.apache.commons.net;
017    
018    import java.io.IOException;
019    import java.io.InputStream;
020    
021    /***
022     * The WhoisClient class implements the client side of the Internet Whois
023     * Protocol defined in RFC 954.   To query a host you create a
024     * WhoisClient instance, connect to the host, query the host, and finally
025     * disconnect from the host.  If the whois service you want to query is on
026     * a non-standard port, connect to the host at that port.
027     * Here's a sample use:
028     * <pre>
029     *    WhoisClient whois;
030     *
031     *    whois = new WhoisClient();
032     *
033     *    try {
034     *      whois.connect(WhoisClient.DEFAULT_HOST);
035     *      System.out.println(whois.query("foobar"));
036     *      whois.disconnect();
037     *    } catch(IOException e) {
038     *      System.err.println("Error I/O exception: " + e.getMessage());
039     *      return;
040     *    }
041     * </pre>
042     *
043     * <p>
044     * <p>
045     * @author Daniel F. Savarese
046     ***/
047    
048    public final class WhoisClient extends FingerClient
049    {
050        /***
051         * The default whois host to query.  It is set to whois.internic.net.
052         ***/
053        public static final String DEFAULT_HOST = "whois.internic.net";
054    
055        /***
056         * The default whois port.  It is set to 43 according to RFC 954.
057         ***/
058        public static final int DEFAULT_PORT = 43;
059    
060    
061        /***
062         * The default whois constructor.    Initializes the
063         * default port to <code> DEFAULT_PORT </code>.
064         ***/
065        public WhoisClient()
066        {
067            setDefaultPort(DEFAULT_PORT);
068        }
069    
070        /***
071         * Queries the connected whois server for information regarding
072         * the given handle.  It is up to the programmer to be familiar with the
073         * handle syntax of the whois server.  You must first connect to a whois
074         * server before calling this method, and you should disconnect afterward.
075         * <p>
076         * @param handle  The handle to lookup.
077         * @return The result of the whois query.
078         * @exception IOException  If an I/O error occurs during the operation.
079         ***/
080        public String query(String handle) throws IOException
081        {
082            return query(false, handle);
083        }
084    
085    
086        /***
087         * Queries the connected whois server for information regarding
088         * the given handle and returns the InputStream of the network connection.
089         * It is up to the programmer to be familiar with the handle syntax
090         * of the whois server.  You must first connect to a finger server before
091         * calling this method, and you should disconnect after finishing reading
092         * the stream.
093         * <p>
094         * @param handle  The handle to lookup.
095         * @return The InputStream of the network connection of the whois query.
096         *         Can be read to obtain whois results.
097         * @exception IOException  If an I/O error occurs during the operation.
098         ***/
099        public InputStream getInputStream(String handle) throws IOException
100        {
101            return getInputStream(false, handle);
102        }
103    
104    }
105