Exemplo n.º 1
0
 def _validate_ranges(self, ipranges):
     for iprange in ipranges:
         ipr = rho_ips.RhoIpRange(iprange)
         if not ipr.valid:
             print _("""ip range "%s" is invalid""" %
                     string.join(ipranges, ','))
             sys.exit(1)
Exemplo n.º 2
0
    def _check_ipr(self, iprange, expected):
        self.ipr = rho_ips.RhoIpRange(iprange)
        list_of_ips = list(self.ipr.ips)
        ips = sorted(map(str, list_of_ips))
        #        list_of_ips = self.ipr.list_ips()
        expected.sort()

        #        print len(ips), len(expected)
        #        print ips[0],ips[-1]
        #        print expected[0], expected[-1]
        #        self._cmp_list(expected, ips)
        #        print  ips, expected
        assert ips == expected
Exemplo n.º 3
0
Arquivo: scanner.py Projeto: wzzrd/rho
    def scan_profiles(self, profilenames):
        missing_profiles = []
        ssh_job_list = []
        for profilename in profilenames:
            profile = self.config.get_profile(profilename)
            if profile is None:
                missing_profiles.append(profilename)
                continue
            ips = []
            for range_str in profile.ranges:
                ipr = rho_ips.RhoIpRange(range_str)
                ips.extend(ipr.list_ips())

            for ip in ips:

                # Create a copy of the list of ports and authnames,
                # we're going to modify them if we have a cache hit:
                ports = list(profile.ports)
                authnames = list(profile.auth_names)

                # If a cache hit, move the port/auth to the start of the list:
                if ip in self.cache:
                    log.debug("Cache hit for: %s" % ip)
                    cached_port = self.cache[ip]['port']
                    log.debug("Cached port: %s %s" %
                              (cached_port, type(cached_port)))
                    cached_authname = self.cache[ip]['auth']
                    if cached_port in ports:
                        ports.remove(cached_port)
                        ports.insert(0, cached_port)
                        log.debug("trying port %s first" % cached_port)
                    if cached_authname in authnames:
                        authnames.remove(cached_authname)
                        authnames.insert(0, cached_authname)
                        log.debug("trying auth %s first" % cached_authname)

                sshj = ssh_jobs.SshJob(ip=ip,
                                       ports=ports,
                                       auths=self._find_auths(authnames),
                                       rho_cmds=self.get_rho_cmds(),
                                       allow_agent=self.allow_agent)
                ssh_job_list.append(sshj)

        self.ssh_jobs.ssh_jobs = ssh_job_list
        self._run_scan()

        return missing_profiles