def to_port_num(str_in):
    """
    Tries to coerce provided argument `str_in` to a port number integer
    value.

    Args:
        str_in (string): String to coerce to port number.

    Returns:
        (int) or (None): Integer port number if provided `str_in` is a valid
                         port number string, None otherwise.
    """

    try:
        port = int(str_in)
        if port<1 or port>65535:
            return None
    except ValueError:
        return None
    return port