def port_str_to_int(port):
    """
    Accepts a string port, validates it is a valid port, and returns it as an int.
    :param port: A string representing a port
    :return: The port as an int, or None if it was not valid.
    """
    try:
        port = int(port)
        if port is None or port < 1024 or port > 49151:
            raise ValueError
        return port
    except ValueError:
        print('"' + str(port) + '" is not a valid port. Must be an integer between 1025 and 49150.')
        return None