1. /*
  2. * Copyright 2001-2004 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. import java.io.IOException;
  18. import java.io.InputStream;
  19. /***
  20. * The WhoisClient class implements the client side of the Internet Whois
  21. * Protocol defined in RFC 954. To query a host you create a
  22. * WhoisClient instance, connect to the host, query the host, and finally
  23. * disconnect from the host. If the whois service you want to query is on
  24. * a non-standard port, connect to the host at that port.
  25. * Here's a sample use:
  26. * <pre>
  27. * WhoisClient whois;
  28. *
  29. * whois = new WhoisClient();
  30. *
  31. * try {
  32. * whois.connect(WhoisClient.DEFAULT_HOST);
  33. * System.out.println(whois.query("foobar"));
  34. * whois.disconnect();
  35. * } catch(IOException e) {
  36. * System.err.println("Error I/O exception: " + e.getMessage());
  37. * return;
  38. * }
  39. * </pre>
  40. *
  41. * <p>
  42. * <p>
  43. * @author Daniel F. Savarese
  44. ***/
  45. public final class WhoisClient extends FingerClient
  46. {
  47. /***
  48. * The default whois host to query. It is set to whois.internic.net.
  49. ***/
  50. public static final String DEFAULT_HOST = "whois.internic.net";
  51. /***
  52. * The default whois port. It is set to 43 according to RFC 954.
  53. ***/
  54. public static final int DEFAULT_PORT = 43;
  55. /***
  56. * The default whois constructor. Initializes the
  57. * default port to <code> DEFAULT_PORT </code>.
  58. ***/
  59. public WhoisClient()
  60. {
  61. setDefaultPort(DEFAULT_PORT);
  62. }
  63. /***
  64. * Queries the connected whois server for information regarding
  65. * the given handle. It is up to the programmer to be familiar with the
  66. * handle syntax of the whois server. You must first connect to a whois
  67. * server before calling this method, and you should disconnect afterward.
  68. * <p>
  69. * @param handle The handle to lookup.
  70. * @return The result of the whois query.
  71. * @exception IOException If an I/O error occurs during the operation.
  72. ***/
  73. public String query(String handle) throws IOException
  74. {
  75. return query(false, handle);
  76. }
  77. /***
  78. * Queries the connected whois server for information regarding
  79. * the given handle and returns the InputStream of the network connection.
  80. * It is up to the programmer to be familiar with the handle syntax
  81. * of the whois server. You must first connect to a finger server before
  82. * calling this method, and you should disconnect after finishing reading
  83. * the stream.
  84. * <p>
  85. * @param handle The handle to lookup.
  86. * @return The InputStream of the network connection of the whois query.
  87. * Can be read to obtain whois results.
  88. * @exception IOException If an I/O error occurs during the operation.
  89. ***/
  90. public InputStream getInputStream(String handle) throws IOException
  91. {
  92. return getInputStream(false, handle);
  93. }
  94. }