Create a Socket that will verify that a given ip with a specific port can be connected or not.
public static boolean isPortOpen(final String ip, final int port, final int timeout) { try { Socket socket = new Socket(); socket.connect(new InetSocketAddress(ip, port), timeout); socket.close(); return true; } catch(ConnectException ce){ ce.printStackTrace(); return false; } catch (Exception ex) { ex.printStackTrace(); return false; } }
source share