Version 1.0

This commit is contained in:
Erik C. Thauvin 2002-07-25 05:24:56 +00:00
commit 4cd29f3eb0
8 changed files with 739 additions and 0 deletions

147
Whois.java Normal file
View file

@ -0,0 +1,147 @@
/*
Package: GeekTools Whois Java Client 1.0
File: Whois.java (Java source file)
Author: Erik C. Thauvin <erik@skytouch.com>
Comments: Part of the GeekTools Whois Java Client package.
See the README.TXT file for more information.
Copyright (C) 2000 SkyTouch Communications. All Rights Reserved.
This program is distributed under the terms of the GNU General
Public License as published by the Free Software Foundation.
See the COPYING.TXT file for more information.
$Id$
*/
import java.net.Socket;
import java.io.*;
import java.util.Properties;
public class Whois
{
// The truth is out there!
public static void main(String[] args)
{
// Display usage if there are no command line arguments
if (args.length < 1)
{
System.out.println(
"Usage: java Whois query[@<whois.server>]");
return;
}
// Default server is whois.geektools.com
String server = "whois.geektools.com";
// Default server port is 43
int port = 43;
// Load the properties file.
try
{
FileInputStream in =
new FileInputStream("Whois.properties");
Properties app = new Properties();
app.load(in);
// Get the server property
server = (app.getProperty("server", server));
// Get the port property
String tmp = app.getProperty("port");
try
{
port = Integer.parseInt(tmp);
}
catch (NumberFormatException e)
{
// Do nothing!
}
in.close();
}
catch (FileNotFoundException e)
{
// Do nothing!
}
catch (IOException e)
{
System.err.println(
"Whois: an error occurred while loading the properties file: "
+ e);
}
// Build the whois query using command line arguments
String query = args[0];
for (int i = 1; i < args.length; i++)
{
query += (" " + args[i]);
}
// The whois server can be specified after "@"
// e.g.: query@whois.networksolutions.com
int at = query.lastIndexOf("@");
int len = query.length();
if ((at != -1))
{
// Remove the @ if last character in query
// e.g.: john@doe.com@
if (at == (len - 1))
{
query = query.substring(0, len - 1);
}
else
{
// The whois server is specified after "@"
server = query.substring(at + 1, len);
// The whois query is specified before "@"
query = query.substring(0, at);
}
}
try
{
// Establish connection to whois server & port
Socket connection = new Socket(server, port);
PrintStream out =
new PrintStream(connection.getOutputStream());
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String line = "";
// Send the whois query
out.println(query);
// Display the whois server's address & port
System.out.println("[" + server + ":" + port + "]");
// Read/display the query's result
while ((line = in.readLine()) != null)
{
System.out.println(line);
}
}
catch (java.net.UnknownHostException e)
{
// Unknown whois server
System.err.println("Whois: unknown host: " + server);
return;
}
catch (IOException e)
{
// Could not connect to whois server
System.err.println("Whois: " + e);
return;
}
}
}