def getHosts(config): hosts = [] # get patterns and replace friendly "*" with regex-correct pattern ".*" patterns = [pattern.replace("*", ".*") for pattern in config['IGNORED_HOSTS']] regex = listToRegex(patterns) while True: needsApprove = False operation = interactiveutils.askMultipleChoiceQuestion("How should I get the names of hosts to search? (default=nmap)", ['nmap', 'hosts', 'manually', 'quit'], 'nmap') if operation == 'nmap': hosts = getHostsViaNMap(config) needsApprove = True elif operation == 'hosts': hosts = getHostsViaHosts() needsApprove = True elif operation == 'manually': interactiveutils.addListItems("Please enter the names of remote hosts to search for log files.", "remote-host", hosts, isValidHost) elif operation == 'quit': break # didn't get any hosts if hosts == None or len(hosts) == 0: print "Unable to get hosts with that method. Please try another method." else: # got some hosts hosts = [host for host in hosts if re.search(regex, host.lower()) == None] hosts.sort() if needsApprove: hosts = interactiveutils.validateElements("hosts", hosts) if len(hosts) > 0: break return hosts
def manualListHosts(): hosts = [] if interactiveutils.askYesNoQuestion( "Would you like to manually enter additional remote host names?", False): interactiveutils.addListItems( "Please enter the names of remote hosts to search for log files.", "remote-host", hosts, isValidHost) return hosts
def getHosts(config): hosts = [] # get patterns and replace friendly "*" with regex-correct pattern ".*" patterns = [ pattern.replace("*", ".*") for pattern in config['IGNORED_HOSTS'] ] regex = listToRegex(patterns) while True: needsApprove = False operation = interactiveutils.askMultipleChoiceQuestion( "How should I get the names of hosts to search? (default=nmap)", ['nmap', 'hosts', 'manually', 'quit'], 'nmap') if operation == 'nmap': hosts = getHostsViaNMap(config) needsApprove = True elif operation == 'hosts': hosts = getHostsViaHosts() needsApprove = True elif operation == 'manually': interactiveutils.addListItems( "Please enter the names of remote hosts to search for log files.", "remote-host", hosts, isValidHost) elif operation == 'quit': break # didn't get any hosts if hosts == None or len(hosts) == 0: print "Unable to get hosts with that method. Please try another method." else: # got some hosts hosts = [ host for host in hosts if re.search(regex, host.lower()) == None ] hosts.sort() if needsApprove: hosts = interactiveutils.validateElements("hosts", hosts) if len(hosts) > 0: break return hosts
def manualListHosts(): hosts = [] if interactiveutils.askYesNoQuestion("Would you like to manually enter additional remote host names?", False): interactiveutils.addListItems("Please enter the names of remote hosts to search for log files.", "remote-host", hosts, isValidHost) return hosts