Пример #1
0
    def searchcountry(country, neg=False):
        """Filters (if `neg` == True, filters out) one particular
        country, or a list of countries.

        """
        country = utils.country_unalias(country)
        if isinstance(country, list):
            res = Q("terms", infos__country_code=country)
        else:
            res = Q("match", infos__country_code=country)
        if neg:
            return ~res
        return res
Пример #2
0
def target_from_args(args):
    if args.country is not None:
        countries = set()
        for country in args.country.split(","):
            ccodes = utils.country_unalias(country)
            if isinstance(ccodes, list):
                countries.update(ccodes)
            else:
                countries.add(ccodes)
        target = reduce(
            add,
            (TargetCountry(
                country,
                categories=args.categories,
                maxnbr=args.limit,
                state=args.state,
            ) for country in countries),
        )
    elif args.registered_country is not None:
        countries = set()
        for country in args.registered_country.split(","):
            ccodes = utils.country_unalias(country)
            if isinstance(ccodes, list):
                countries.update(ccodes)
            else:
                countries.add(ccodes)
        target = reduce(
            add,
            (TargetRegisteredCountry(
                country,
                categories=args.categories,
                maxnbr=args.limit,
                state=args.state,
            ) for country in countries),
        )
    elif args.city is not None:
        target = TargetCity(
            args.city[0],
            args.city[1],
            categories=args.categories,
            maxnbr=args.limit,
            state=args.state,
        )
    elif args.region is not None:
        target = TargetRegion(
            args.region[0],
            args.region[1],
            categories=args.categories,
            maxnbr=args.limit,
            state=args.state,
        )
    elif args.asnum is not None:
        target = reduce(
            add,
            (TargetAS(
                asnum,
                categories=args.categories,
                maxnbr=args.limit,
                state=args.state,
            ) for asnum in args.asnum.split(",")),
        )
    elif args.range is not None:
        target = TargetRange(
            args.range[0],
            args.range[1],
            categories=args.categories,
            maxnbr=args.limit,
            state=args.state,
        )
    elif args.network is not None:
        target = TargetNetwork(
            args.network,
            categories=args.categories,
            maxnbr=args.limit,
            state=args.state,
        )
    elif args.routable:
        target = TargetRoutable(categories=args.categories,
                                maxnbr=args.limit,
                                state=args.state)
    elif args.file is not None:
        target = TargetFile(args.file,
                            categories=args.categories,
                            state=args.state)
    elif args.test is not None:
        target = TargetTest(args.test,
                            categories=args.categories,
                            maxnbr=args.limit,
                            state=args.state)
    else:
        return None
    if args.zmap_prescan_port is not None:
        if args.zmap_prescan_opts is None:
            zmap_prescan_opts = []
        else:
            zmap_prescan_opts = shlex.split(args.zmap_prescan_opts)
        if "-b" not in zmap_prescan_opts:
            zmap_prescan_opts += ["-b", os.devnull]
        return TargetZMapPreScan(
            target,
            port=args.zmap_prescan_port,
            zmap_opts=zmap_prescan_opts,
        )
    if args.nmap_prescan_ports is not None:
        if args.nmap_prescan_opts is None:
            nmap_prescan_opts = []
        else:
            nmap_prescan_opts = shlex.split(args.nmap_prescan_opts)
        return TargetNmapPreScan(target,
                                 ports=args.nmap_prescan_ports,
                                 nmap_opts=nmap_prescan_opts)
    return target