package primer2;

import java.net.*;
import java.util.Date;
import java.io.*;

public class HighPortScanner {

	public static void main(String[] args) {

		String host = "localhost";

		if (args.length > 0)
			host = args[0];

		try {
			InetAddress theAddress = InetAddress.getByName(host);

			System.out.println("Trenutak pocetka: " + new Date());

			for (int i = 1024; i < 65536; i++) {
				try (Socket theSocket = new Socket(theAddress, i);) {

					if (i % 1000 == 0)
						System.out.println("\t\tIspituje port: " + i);

					System.out.println("There is a server on port " + i + " of " + host);
					System.out.println(" nadjen: " + new Date());
				} catch (IOException ex) {

				}

			}

			System.out.println("Trenutak kraja: " + new Date());
		} catch (UnknownHostException ex) {
			System.err.println(ex);
		}

	}

}
