def handle_results(self, results, session_key, in_preview): # Get the index to output to index = get_default_index(session_key) # Make sure that the host field was provided if self.host is None: self.logger.warn("No host was provided") return if results is None or len(results) == 0: # FYI: we ignore results since this is a generating command # Get the index if self.index is not None: index = self.index else: index = get_default_index(session_key) # Do the whois output = whois(host=self.host, index=index, logger=self.logger) # Convert the output to a series of rows for better output in the search output processed = dict_to_table(output) # Sort the items processed = sorted(processed, key=lambda e: e['attribute']) # Output the results self.output_results(processed) else: # Make a cache to store previously looked up results cache = {} for result in results: # Process each result if self.field in result: host_to_lookup = result[self.field] # See if we looked up the host already if host_to_lookup in cache: output = cache[host_to_lookup] # Otherwise, pull the host from the cache else: output = whois(host=host_to_lookup, index=index, logger=self.logger) cache[host_to_lookup] = output # Add the output result.update(output) # Output the results self.output_results(results)
def test_do_whois(self): """ Test an IP whois """ output = whois('173.255.235.229') self.assertGreater(len(output), 0)
def get_whois(self, request_info, host=None, **kwargs): """ Perform a whois. """ if host is None: return self.render_error_json( "Unable to perform network operation: no host argument provided" ) try: output = whois(host, source="network_tools_controller", logger=logger) # Everything worked, return accordingly return { 'payload': output, # Payload of the request. 'status': 200 # HTTP status code } except: self.logger.exception( "Exception generated when attempting to perform an operation") return self.render_error_json( "Unable to perform network operation")
def test_do_whois_domain(self): """ Test a domain whois """ output = whois('textcritical.net') self.assertGreater(len(output), 0)
def do_lookup(self, host): """ Perform a whois lookup against the given host. """ self.logger.info("Running whois against host=%s", host) output = whois(host=host, index=None) return translate(output, self.TRANSLATION_RULES)
def do_lookup(self, host): """ Perform a whois lookup against the given host. """ index = get_default_index() self.logger.info("Running whois against host=%s using index=%s", host, index) output = whois(host=host, index=index, logger=self.logger) return translate(output, self.TRANSLATION_RULES)