code: public static int getNextAvailable(int fromPort) {
          if (fromPort < MIN_PORT_NUMBER || fromPort > MAX_PORT_NUMBER) {
              throw new IllegalArgumentException("Invalid start port: "
                      + fromPort);
          }
  
          for (int i = fromPort; i <= MAX_PORT_NUMBER; i++) {
              if (available(i)) {
                  return i;
              }
          }
  
          throw new NoSuchElementException("Could not find an available port "
                  + "above " + fromPort);
      }
docs: Gets the next available port starting at a port.
  
  @param fromPort the port to scan for availability
  @throws NoSuchElementException if there are no ports available