/* 

David Tate
How easy is Java?  This easy. 

*/

import java.net.*;
import java.io.*;


public class PortScanner {
	public static void main(String[] args) {

		if (args.length <= 0) {
			System.out.println("Please specifiy some hosts.");
			System.exit(0);
		}

		String host = null;
		Socket connection = null;

		for (int i = 0; i < args.length; i++) {
			host = args[i];
			System.out.println("#" + host + "#");
    	
    		try {
      		InetAddress theAddress = InetAddress.getByName(host);
      		for (int j = 1; j < 65536; j++) {
        			try {
          			connection = new Socket(host, j);
          			System.out.println(j);
        			}
        			catch (IOException e) {
						/* Nothing to see here, move along. */
        			}
      		}  
    		} 
    		catch (UnknownHostException e) {
      		System.err.println(e);
    		}
    		finally {
      		try {
        			if (connection != null) connection.close(); 
      		}
      		catch (IOException e) { /* Nothing we can do about this. */ }
			}
		}  
	}  
}

