Mega Code Archive

 
Categories / Java / Network Protocol
 

This finger client allows you to query a remote host

/*        Chapter 3 - Simple Protocols Java 2 Network Protocols Black Book by Al Williams     Paraglyph Press 2001 */ import java.net.*; import java.io.*; public class Finger {     public String finger(String host, String users)         throws IOException, SocketException {        String outstring="";        int c=0;        Socket sock=new Socket(host,79);        OutputStream os = sock.getOutputStream();        InputStream is = sock.getInputStream();        users = users + "\r\n";        os.write(users.getBytes("iso8859_1"));        try {            while (c!=-1) {              c=is.read();              if (c!=-1) outstring+=(char)c;            }        }        catch (IOException e) {}        return outstring;     }     public static void main(String[] args) {             String hostname = "";        String ulist = "";        if (args.length==0) {            System.out.println("usage: finger host [user]");            System.exit(1);        }        if (args.length>=2)             for (int i=1; i<args.length; i++)               ulist+=args[i]+" ";        hostname=args[0];        Finger worker = new Finger();        try {          System.out.println(worker.finger(hostname,ulist.trim()));        }        catch (Exception e) {            System.out.println(e);        }     } }