public static boolean isTcpPortAvailable(final int port) {
        try (val serverSocket = new ServerSocket()) {
            serverSocket.setReuseAddress(false);
            serverSocket.bind(new InetSocketAddress(InetAddress.getByName("localhost"), port), 1);
            return true;
        } catch (final Exception ex) {
            return false;
        }
    }
Is tcp port available.

@param port the port
@return true/false
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/SocketUtils.java