/*   
     Finger client
     [coded by Arul John] <http://wolf.rules.it>
*/

import java.io.*;
import java.net.*;

class Finger {
    public static void main(String args[]) {
	try {
	    if (args.length < 2) {
		System.out.println("Usage : java Finger <hostname> <userlist separated by spaces>");
		System.exit(0);
	    }
	    String url = args[0];
	    String users = "";
	    for (int i = 1; i < args.length; i++) {
		users += " " + args[i];
	    }
	    users = users.trim();
	    System.out.println("This is slow, so please wait....");
	    Socket s = new Socket(url, 79);
	    BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
	    DataOutputStream dos = new DataOutputStream(s.getOutputStream());
	    dos.writeBytes(users);
	    dos.writeByte(13);
	    dos.writeByte(10);
	    dos.flush();
	    String inData = reader.readLine();
	    System.out.println(inData);
	    while ((inData = reader.readLine()) != null) {
		System.out.println(inData);
	    }
	    dos.close();
	    reader.close();
	} catch (Exception e) {
	    System.err.println("Enter the input correctly! Its possible that the host has a firewall!!");
	}
    }
}
