@Test public void find_open_ports_with_random_open() throws Exception { generate_port_spawn(10); PortListener pl = new PortListener(); ScanListener sl = new ScanListener(); open_random_ports(1, 3, m_pmin - 5, m_pmin - 1); open_random_ports(1, 3, m_pmax + 1, m_pmax + 5); int inside[] = open_random_ports(1, 5, m_pmin, m_pmax); RmiClientDiscovery.find_open_ports("localhost", m_pmin, m_pmax, pl, sl); assertEquals(inside.length, pl.m_ports.length); assertEquals(10, sl.m_count); assertEquals(m_pmin, sl.m_min); assertEquals(m_pmax, sl.m_max); }
public static void find_open_ports(String host, int min_port, int max_port, PortFoundListener listener, PortScanListener scan_listener) { if (host == null) { throw new IllegalArgumentException("host == null"); } if (listener == null) { throw new IllegalArgumentException("listener == null"); } if (min_port <= 0) { throw new IllegalArgumentException("minPort <= 0"); } if (max_port < min_port) { throw new IllegalArgumentException("maxPort < minPort"); } for (int i = min_port; i <= max_port; i++) { try (Socket s = new Socket()) { s.connect(new InetSocketAddress(host, i), MAX_WAIT_OPEN_MS); if (scan_listener != null) { scan_listener.port_scanned(i); } s.close(); listener.port_found(i); } catch (IOException e) { if (scan_listener != null) { scan_listener.port_scanned(i); } } } }
RmiClientDiscovery { public static void find_open_ports(String host, int min_port, int max_port, PortFoundListener listener, PortScanListener scan_listener) { if (host == null) { throw new IllegalArgumentException("host == null"); } if (listener == null) { throw new IllegalArgumentException("listener == null"); } if (min_port <= 0) { throw new IllegalArgumentException("minPort <= 0"); } if (max_port < min_port) { throw new IllegalArgumentException("maxPort < minPort"); } for (int i = min_port; i <= max_port; i++) { try (Socket s = new Socket()) { s.connect(new InetSocketAddress(host, i), MAX_WAIT_OPEN_MS); if (scan_listener != null) { scan_listener.port_scanned(i); } s.close(); listener.port_found(i); } catch (IOException e) { if (scan_listener != null) { scan_listener.port_scanned(i); } } } } }
RmiClientDiscovery { public static void find_open_ports(String host, int min_port, int max_port, PortFoundListener listener, PortScanListener scan_listener) { if (host == null) { throw new IllegalArgumentException("host == null"); } if (listener == null) { throw new IllegalArgumentException("listener == null"); } if (min_port <= 0) { throw new IllegalArgumentException("minPort <= 0"); } if (max_port < min_port) { throw new IllegalArgumentException("maxPort < minPort"); } for (int i = min_port; i <= max_port; i++) { try (Socket s = new Socket()) { s.connect(new InetSocketAddress(host, i), MAX_WAIT_OPEN_MS); if (scan_listener != null) { scan_listener.port_scanned(i); } s.close(); listener.port_found(i); } catch (IOException e) { if (scan_listener != null) { scan_listener.port_scanned(i); } } } }  }
RmiClientDiscovery { public static void find_open_ports(String host, int min_port, int max_port, PortFoundListener listener, PortScanListener scan_listener) { if (host == null) { throw new IllegalArgumentException("host == null"); } if (listener == null) { throw new IllegalArgumentException("listener == null"); } if (min_port <= 0) { throw new IllegalArgumentException("minPort <= 0"); } if (max_port < min_port) { throw new IllegalArgumentException("maxPort < minPort"); } for (int i = min_port; i <= max_port; i++) { try (Socket s = new Socket()) { s.connect(new InetSocketAddress(host, i), MAX_WAIT_OPEN_MS); if (scan_listener != null) { scan_listener.port_scanned(i); } s.close(); listener.port_found(i); } catch (IOException e) { if (scan_listener != null) { scan_listener.port_scanned(i); } } } }  static void find_open_ports(String host, int min_port, int max_port,
			PortFoundListener listener, PortScanListener scan_listener); static T find_rmi_client(String host, int port,
			Class<T> iface); static void find_rmi_client(final String host, int min_port,
			int max_port, final Class<?> iface,
			final ClientFoundListener listener,
			PortScanListener scan_listener); static void find_rmi_client(String host, Class<?> iface,
			ClientFoundListener listener, PortScanListener scan_listener); }
RmiClientDiscovery { public static void find_open_ports(String host, int min_port, int max_port, PortFoundListener listener, PortScanListener scan_listener) { if (host == null) { throw new IllegalArgumentException("host == null"); } if (listener == null) { throw new IllegalArgumentException("listener == null"); } if (min_port <= 0) { throw new IllegalArgumentException("minPort <= 0"); } if (max_port < min_port) { throw new IllegalArgumentException("maxPort < minPort"); } for (int i = min_port; i <= max_port; i++) { try (Socket s = new Socket()) { s.connect(new InetSocketAddress(host, i), MAX_WAIT_OPEN_MS); if (scan_listener != null) { scan_listener.port_scanned(i); } s.close(); listener.port_found(i); } catch (IOException e) { if (scan_listener != null) { scan_listener.port_scanned(i); } } } }  static void find_open_ports(String host, int min_port, int max_port,
			PortFoundListener listener, PortScanListener scan_listener); static T find_rmi_client(String host, int port,
			Class<T> iface); static void find_rmi_client(final String host, int min_port,
			int max_port, final Class<?> iface,
			final ClientFoundListener listener,
			PortScanListener scan_listener); static void find_rmi_client(String host, Class<?> iface,
			ClientFoundListener listener, PortScanListener scan_listener);  }