    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
    018package org.apache.commons.net.whois;
    019
    020import java.io.IOException;
    021import java.io.InputStream;
    022
    023import org.apache.commons.net.finger.FingerClient;
    024
    025/**
    026 * The WhoisClient class implements the client side of the Internet Whois Protocol defined in RFC 954. To query a host you create a WhoisClient instance,
    027 * connect to the host, query the host, and finally disconnect from the host. If the whois service you want to query is on a non-standard port, connect to the
    028 * host at that port. Here's a sample use:
    029 *
    030 * <pre>
    031 * WhoisClient whois;
    032 *
    033 * whois = new WhoisClient();
    034 *
    035 * try {
    036 *     whois.connect(WhoisClient.DEFAULT_HOST);
    037 *     System.out.println(whois.query("foobar"));
    038 *     whois.disconnect();
    039 * } catch (IOException e) {
    040 *     System.err.println("Error I/O exception: " + e.getMessage());
    041 *     return;
    042 * }
    043 * </pre>
    044 *
    045 *
    046 *
    047 */
    048
    049public final class WhoisClient extends FingerClient {
    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     * The default whois constructor. Initializes the default port to <code> DEFAULT_PORT </code>.
    062     */
    063    public WhoisClient() {
    064        setDefaultPort(DEFAULT_PORT);
    065    }
    066
    067    /**
    068     * Queries the connected whois server for information regarding the given handle and returns the InputStream of the network connection. It is up to the
    069     * programmer to be familiar with the handle syntax of the whois server. You must first connect to a finger server before calling this method, and you
    070     * should disconnect after finishing reading the stream.
    071     *
    072     * @param handle The handle to lookup.
    073     * @return The InputStream of the network connection of the whois query. Can be read to obtain whois results.
    074     * @throws IOException If an I/O error occurs during the operation.
    075     */
    076    public InputStream getInputStream(final String handle) throws IOException {
    077        return getInputStream(false, handle);
    078    }
    079
    080    /**
    081     * Queries the connected whois server for information regarding the given handle. It is up to the programmer to be familiar with the handle syntax of the
    082     * whois server. You must first connect to a whois server before calling this method, and you should disconnect afterward.
    083     *
    084     * @param handle The handle to lookup.
    085     * @return The result of the whois query.
    086     * @throws IOException If an I/O error occurs during the operation.
    087     */
    088    public String query(final String handle) throws IOException {
    089        return query(false, handle);
    090    }
    091
    092}