'Filters records with open port number between minn and maxn'

@staticmethod
def searchcountopenports(minn=None, maxn=None, neg=False):

    assert ((minn is not None) or (maxn is not None))
    req = select([column('scan')]).select_from(select([Port.scan.label('scan'), func.count().label('count')]).where((Port.state == 'open')).group_by(Port.scan).alias('pcnt'))
    if (minn == maxn):
        req = req.where((column('count') == minn))
    else:
        if (minn is not None):
            req = req.where((column('count') >= minn))
        if (maxn is not None):
            req = req.where((column('count') <= maxn))
    return NmapFilter(main=(Scan.id.notin_(req) if neg else Scan.id.in_(req)))
