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 ***/ 050 051 public final class WhoisClient extends FingerClient 052 { 053 /*** 054 * The default whois host to query. It is set to whois.internic.net. 055 ***/ 056 public static final String DEFAULT_HOST = "whois.internic.net"; 057 058 /*** 059 * The default whois port. It is set to 43 according to RFC 954. 060 ***/ 061 public static final int DEFAULT_PORT = 43; 062 063 064 /*** 065 * The default whois constructor. Initializes the 066 * default port to <code> DEFAULT_PORT </code>. 067 ***/ 068 public WhoisClient() 069 { 070 setDefaultPort(DEFAULT_PORT); 071 } 072 073 /*** 074 * Queries the connected whois server for information regarding 075 * the given handle. It is up to the programmer to be familiar with the 076 * handle syntax of the whois server. You must first connect to a whois 077 * server before calling this method, and you should disconnect afterward. 078 * <p> 079 * @param handle The handle to lookup. 080 * @return The result of the whois query. 081 * @exception IOException If an I/O error occurs during the operation. 082 ***/ 083 public String query(String handle) throws IOException 084 { 085 return query(false, handle); 086 } 087 088 089 /*** 090 * Queries the connected whois server for information regarding 091 * the given handle and returns the InputStream of the network connection. 092 * It is up to the programmer to be familiar with the handle syntax 093 * of the whois server. You must first connect to a finger server before 094 * calling this method, and you should disconnect after finishing reading 095 * the stream. 096 * <p> 097 * @param handle The handle to lookup. 098 * @return The InputStream of the network connection of the whois query. 099 * Can be read to obtain whois results. 100 * @exception IOException If an I/O error occurs during the operation. 101 ***/ 102 public InputStream getInputStream(String handle) throws IOException 103 { 104 return getInputStream(false, handle); 105 } 106 107 } 108