List of utility methods to do HTTP Port Find
boolean | isPortFree(String hostName, String port) Checks whether the given port is free on the specified host NOTE: works properly only on local host try { return isPortFree(hostName, Integer.parseInt(port)); } catch (Exception e) { return false; |
boolean | isPortFreeClient(String hostName, int portNumber) is Port Free Client try { if (hostName == null) { hostName = getHostName(); Socket socket = new Socket(hostName, portNumber); OutputStream os = socket.getOutputStream(); InputStream is = socket.getInputStream(); os.close(); ... |
Boolean | isPortInUse(final String host, final Integer port) is Port In Use Boolean result = false; try { (new Socket(host, port)).close(); result = true; } catch (IOException ex) { return result; |
boolean | isPortInUse(int port) Checks if the given port is already used if (port < 0 || port >= 65536) { return false; try (ServerSocket socket = new ServerSocket(port)) { return false; } catch (IOException e) { return true; |
boolean | isPortOnUse(int port) is Port On Use boolean isUse = false; ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(port); isUse = false; } catch (IOException e) { e.printStackTrace(); isUse = true; ... |
boolean | isPortOpen(int port) is Port Open return isPortOpen(new InetSocketAddress("localhost", port)); |
boolean | isPortOpen(int port, String host) Check whether the provided port is open Socket socket = null; boolean isPortOpen; try { socket = new Socket(host, port); isPortOpen = socket.isConnected(); } catch (IOException e) { isPortOpen = false; } finally { ... |
boolean | isPortOpen(String host, int port) is Port Open InetSocketAddress socketAddress = new InetSocketAddress(host, port); Socket socket = null; try { socket = new Socket(); socket.setReuseAddress(false); socket.setSoLinger(false, 1); socket.setSoTimeout(TIMEOUT_IN_MILLISECONDS); socket.connect(socketAddress, TIMEOUT_IN_MILLISECONDS); ... |
boolean | isPortUsed(final int portNumber, final String host) is Port Used boolean isPortUsed; ServerSocket serverSocket = null; try { InetAddress inetAddress = InetAddress.getByName(host); serverSocket = new ServerSocket(portNumber, 50, inetAddress); isPortUsed = false; } catch (IOException ignored) { isPortUsed = true; ... |
boolean | isPortUsed(int port) is Port Used ServerSocket serverSocket = new ServerSocket(port); return true; |