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