def inlist()

in blocky-client.py [0:0]


def inlist(banlist, ip, canContain=True):
    """ Check if an IP or CIDR is listed in iptables,
    either by itself or contained within a block (or the reverse) """
    lines = []
    if '/0' in ip:  # DO NOT WANT
        return lines
    # First, check verbatim
    for entry in banlist:
        if entry['source'] == ip:
            lines.append(entry)
    # Check if block, then check for matches within
    if '/' in ip:
        me = netaddr.IPNetwork(ip)
        for entry in banlist:
            them = entry['asNet']
            if them in me:
                if canContain or (len(them) >= len(me)):
                    lines.append(entry)

    # Then the reverse; IP found within blocks?
    else:
        me = netaddr.IPAddress(ip)
        for entry in banlist:
            if '/' in entry['source'] and '/0' not in entry['source']:  # blocks, but not /0
                them = entry['asNet']
                if me in them:
                    lines.append(entry)
    return lines