def domain_info(domain): """Get as much information as possible for a given domain name.""" registered_domain = get_registered_domain(domain) if utils.is_valid_ip_address(domain) or registered_domain == '': error = "`%s` is an invalid domain." % domain raise errors.SatoriInvalidDomain(error) result = pythonwhois.get_whois(registered_domain) registrar = [] if 'registrar' in result and len(result['registrar']) > 0: registrar = result['registrar'][0] nameservers = result.get('nameservers', []) days_until_expires = None expires = None if 'expiration_date' in result: if (isinstance(result['expiration_date'], list) and len(result['expiration_date']) > 0): expires = result['expiration_date'][0] if isinstance(expires, datetime.datetime): days_until_expires = (expires - datetime.datetime.now()).days expires = utils.get_time_string(time_obj=expires) else: days_until_expires = (utils.parse_time_string(expires) - datetime.datetime.now()).days return { 'name': registered_domain, 'whois': result['raw'], 'registrar': registrar, 'nameservers': nameservers, 'days_until_expires': days_until_expires, 'expiration_date': expires, }
def ip_info(ip_address): """Get as much information as possible for a given ip address.""" if not utils.is_valid_ip_address(ip_address): error = "`%s` is an invalid IP address." % ip_address raise errors.SatoriInvalidIP(error) result = pythonwhois.get_whois(ip_address) return { 'whois': result['raw'] }
def run(target, config=None, interactive=False): """Run discovery and return results.""" if config is None: config = {} found = {} resources = {} errors = {} results = { 'target': target, 'created': utils.get_time_string(), 'found': found, 'resources': resources, } if utils.is_valid_ip_address(target): ip_address = target else: hostname = dns.parse_target_hostname(target) found['hostname'] = hostname ip_address = six.text_type(dns.resolve_hostname(hostname)) # TODO(sam): Use ipaddress.ip_address.is_global # .is_private # .is_unspecified # .is_multicast # To determine address "type" if not ipaddress.ip_address(ip_address).is_loopback: try: domain_info = dns.domain_info(hostname) resource_type = 'OS::DNS::Domain' identifier = '%s:%s' % (resource_type, hostname) resources[identifier] = { 'type': resource_type, 'key': identifier, } found['domain-key'] = identifier resources[identifier]['data'] = domain_info if 'registered' in domain_info: found['registered-domain'] = domain_info['registered'] except shared.WhoisException as exc: results['domain'] = str(exc) found['ip-address'] = ip_address host, host_errors = discover_host(ip_address, config, interactive=interactive) if host_errors: errors.update(host_errors) key = host.get('key') or ip_address resources[key] = host found['host-key'] = key results['updated'] = utils.get_time_string() return results, errors
def run(target, config=None, interactive=False): """Run discovery and return results.""" if config is None: config = {} found = {} resources = {} errors = {} results = { 'target': target, 'created': utils.get_time_string(), 'found': found, 'resources': resources, } if utils.is_valid_ip_address(target): ip_address = target else: hostname = dns.parse_target_hostname(target) found['hostname'] = hostname ip_address = six.text_type(dns.resolve_hostname(hostname)) #TODO(sam): Use ipaddress.ip_address.is_global # " .is_private # " .is_unspecified # " .is_multicast # To determine address "type" if not ipaddress.ip_address(ip_address).is_loopback: try: domain_info = dns.domain_info(hostname) resource_type = 'OS::DNS::Domain' identifier = '%s:%s' % (resource_type, hostname) resources[identifier] = { 'type': resource_type, 'key': identifier, } found['domain-key'] = identifier resources[identifier]['data'] = domain_info if 'registered' in domain_info: found['registered-domain'] = domain_info['registered'] except shared.WhoisException as exc: results['domain'] = str(exc) found['ip-address'] = ip_address host, host_errors = discover_host(ip_address, config, interactive=interactive) if host_errors: errors.update(host_errors) key = host.get('key') or ip_address resources[key] = host found['host-key'] = key results['updated'] = utils.get_time_string() return results, errors
def run(address, config=None, interactive=False): """Run discovery and return results.""" if config is None: config = {} results = {} if utils.is_valid_ip_address(address): ipaddress = address else: ipaddress = dns.resolve_hostname(address) #TODO(sam): Use ipaddress.ip_address.is_global # " .is_private # " .is_unspecified # " .is_multicast # To determine address "type" if not ipaddress_module.ip_address(unicode(ipaddress)).is_loopback: try: results['domain'] = dns.domain_info(address) except shared.WhoisException as exc: results['domain'] = str(exc) results['address'] = ipaddress results['host'] = host = {'type': 'Undetermined'} if config.get('username'): server = find_nova_host(ipaddress, config) if server: host['type'] = 'Nova instance' host['uri'] = [ l['href'] for l in server.links if l['rel'] == 'self' ][0] host['name'] = server.name host['id'] = server.id host['addresses'] = server.addresses if config.get('system_info'): module_name = config['system_info'].replace("-", "_") if '.' not in module_name: module_name = 'satori.sysinfo.%s' % module_name system_info_module = utils.import_object(module_name) result = system_info_module.get_systeminfo(ipaddress, config, interactive=interactive) host['system_info'] = result return results
def run(address, config=None, interactive=False): """Run discovery and return results.""" if config is None: config = {} results = {} if utils.is_valid_ip_address(address): ipaddress = address else: ipaddress = dns.resolve_hostname(address) #TODO(sam): Use ipaddress.ip_address.is_global # " .is_private # " .is_unspecified # " .is_multicast # To determine address "type" if not ipaddress_module.ip_address(unicode(ipaddress)).is_loopback: try: results['domain'] = dns.domain_info(address) except shared.WhoisException as exc: results['domain'] = str(exc) results['address'] = ipaddress results['host'] = host = {'type': 'Undetermined'} if config.get('username'): server = find_nova_host(ipaddress, config) if server: host['type'] = 'Nova instance' host['uri'] = [l['href'] for l in server.links if l['rel'] == 'self'][0] host['name'] = server.name host['id'] = server.id host['addresses'] = server.addresses if config.get('system_info'): module_name = config['system_info'].replace("-", "_") if '.' not in module_name: module_name = 'satori.sysinfo.%s' % module_name system_info_module = utils.import_object(module_name) result = system_info_module.get_systeminfo(ipaddress, config, interactive=interactive) host['system_info'] = result return results
def netloc_info(netloc): """Determine if netloc is an IP or domain name.""" if utils.is_valid_ip_address(netloc): ip_info(netloc) else: domain_info(netloc)