import java.net.*;
import java.io.*;public class Whois { public final static int port = 43;
public final static String hostname = "whois.internic.net"; public static void main(String[] args)
{
Socket theSocket;
InputStreamReader iStreamReader;
DataInputStream theWhoisStream;
BufferedReader bf;
PrintStream ps;
// 检查命令行参数
if (args.length <1)
{
System.out.println(" Usage: java whois <command>");
System.out.println("Parameters:");
System.out.println(" command = one or more Domain name, or other command.");
System.out.println("Example:");
System.out.println(" java whois sohu.com");
System.out.println(" java whois help");
// System.exit(1); // 退出
}
try{
// 在TCP服务端口43(十进制)连接SRI-NIC服务主机
theSocket = new Socket(hostname, port);
ps = new PrintStream(theSocket.getOutputStream());
// 发送用户提供的一个或多个命令
for (int i = 0; i < args.length; i++)
ps.print(args[i]+" ");
// 以回车和换行(<CRLF>)结尾
ps.print("\n");
// 接受相应命令的返回信息
iStreamReader = new InputStreamReader(theSocket.getInputStream());
//theWhoisStream = new DataInputStream(theSocket.getInputStream());
bf = new BufferedReader(iStreamReader);
String s;
while ((s = bf.readLine()) != null) {
System.out.println(s);
}
// 关闭DataInputStream和PrintWriter
bf.close();
ps.close();
//关闭socket
theSocket.close();
}
catch (IOException e) {
System.err.println(e);
}
}
}
import java.io.*;public class Whois { public final static int port = 43;
public final static String hostname = "whois.internic.net"; public static void main(String[] args)
{
Socket theSocket;
InputStreamReader iStreamReader;
DataInputStream theWhoisStream;
BufferedReader bf;
PrintStream ps;
// 检查命令行参数
if (args.length <1)
{
System.out.println(" Usage: java whois <command>");
System.out.println("Parameters:");
System.out.println(" command = one or more Domain name, or other command.");
System.out.println("Example:");
System.out.println(" java whois sohu.com");
System.out.println(" java whois help");
// System.exit(1); // 退出
}
try{
// 在TCP服务端口43(十进制)连接SRI-NIC服务主机
theSocket = new Socket(hostname, port);
ps = new PrintStream(theSocket.getOutputStream());
// 发送用户提供的一个或多个命令
for (int i = 0; i < args.length; i++)
ps.print(args[i]+" ");
// 以回车和换行(<CRLF>)结尾
ps.print("\n");
// 接受相应命令的返回信息
iStreamReader = new InputStreamReader(theSocket.getInputStream());
//theWhoisStream = new DataInputStream(theSocket.getInputStream());
bf = new BufferedReader(iStreamReader);
String s;
while ((s = bf.readLine()) != null) {
System.out.println(s);
}
// 关闭DataInputStream和PrintWriter
bf.close();
ps.close();
//关闭socket
theSocket.close();
}
catch (IOException e) {
System.err.println(e);
}
}
}
其他语句在<% %>中