def ip_in_ip_mask(ip, mask_ip, mask):
    '''
    Checks whether an ip is contained in an ip subnet where the subnet is stated as an ip in the dotted format, and a hex mask
    '''
    ip = ip2hex(ip)
    if ip is None: raise Exception("bad ip format")
    if (mask_ip & mask) == (ip & mask):
        return True
    return False