当前位置: 首页>>代码示例>>Python>>正文


Python IPWhois.lookup_rdap方法代码示例

本文整理汇总了Python中ipwhois.IPWhois.lookup_rdap方法的典型用法代码示例。如果您正苦于以下问题:Python IPWhois.lookup_rdap方法的具体用法?Python IPWhois.lookup_rdap怎么用?Python IPWhois.lookup_rdap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ipwhois.IPWhois的用法示例。


在下文中一共展示了IPWhois.lookup_rdap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _whois

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def _whois(ip_pk):
    ip = IPv4Whois.objects.get(pk=ip_pk)
    ip.status = IPv4Whois.STATUS_LOOKING_UP_WHOIS
    ip.save()

    obj = IPWhois(ip.address, timeout=9)

    try:
        results = obj.lookup_rdap()
    except Exception as exc:
        ip.status = IPv4Whois.STATUS_LOOKUP_WHOIS_FAILED
        ip.save()
        raise exc

    ip.whois = json.dumps(results)
    ip.status = IPv4Whois.STATUS_LOOKUP_WHOIS_SUCCESS
    ip.save()

    kafka_msg = {
        'IP': ip.address,
        'Whois': results,
        'Host': settings.EXTERNAL_IP,
        'Timestamp': datetime.utcnow().isoformat(),
    }
    send_to_kafka('results', kafka_msg)
开发者ID:marklit,项目名称:mass-ipv4-whois,代码行数:27,代码来源:tasks.py

示例2: main

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def main(ip):
    obj = IPWhois(ip)
    try:
        results = obj.lookup_rdap(depth=1)
    except:
        results = None
    return results
开发者ID:KunalAggarwal,项目名称:datasploit,代码行数:9,代码来源:ip_whois.py

示例3: cmd_whois_ip

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def cmd_whois_ip(ip):
    """Simple whois client to check IP addresses (IPv4 and IPv6).

    Example:

    \b
    $ habu.whois.ip 8.8.8.8
    {
        "nir": null,
        "asn_registry": "arin",
        "asn": "15169",
        "asn_cidr": "8.8.8.0/24",
        "asn_country_code": "US",
        "asn_date": "1992-12-01",
        "asn_description": "GOOGLE - Google LLC, US",
        "query": "8.8.8.8",
        ...
    """

    warnings.filterwarnings("ignore")

    obj = IPWhois(ip)
    data = obj.lookup_rdap()

    print(json.dumps(data, indent=4))
开发者ID:coolsnake,项目名称:habu,代码行数:27,代码来源:cmd_whois_ip.py

示例4: get_remote_whos

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
 def get_remote_whos(url):
     try:
         obj = IPWhois(DomainCheck.get_remote_IP(url))
         results = obj.lookup_rdap(depth=1)
         pprint(results)
     except socket.error:
         print("Error no connection .. WHOS")
开发者ID:Delfyn,项目名称:Python_webscanner,代码行数:9,代码来源:Scanner.py

示例5: get_ipwhois

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
    def get_ipwhois(self, depth=1):

        # Perform the RDAP lookup for self.addr retrieving all
        # entities up to depth.
        obj = IPWhois(self.addr)
        ret = obj.lookup_rdap(depth=depth)

        # Set the updated timestamp for cache expiration.
        ret['updated'] = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')

        return ret
开发者ID:grcninja,项目名称:ipwhois,代码行数:13,代码来源:redis_cache.py

示例6: lookup

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def lookup(ip, rdap=False):
    obj = IPWhois(ip)
    if rdap:
        # TODO: RDAP output includes less relevant info, needs a dedicated formatter
        return obj.lookup_rdap()
    else:
        ret = obj.lookup_whois()
        # remove some fields that clutter
        for x in ['raw', 'raw_referral', 'referral']:
            ret.pop(x, None)
        return ret
开发者ID:mbch331,项目名称:whois-gateway,代码行数:13,代码来源:gateway.py

示例7: ip_geography

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def ip_geography( ip = None ,
			      key_file = None ) :
			"""

			:param ip:
			:param key_file:
			:return:
			"""


			key = str()
			b_ret = False
			out = str()

			if ip is None or key_file is None :
				raise ValueError( 'bad parameter list' )


			with open( key_file  )as f  :
				key = f.readline().strip()

			try :

				req = 'http://api.ipinfodb.com//v3/ip-city/?key=%s&format=json&ip=%s' % \
					  ( key , ip )

				r = requests.get( req )
				x = r.json()
				for item in  x  :
					out += '%s : %s\n' % ( item , x[item] )


				obj = IPWhois( ip )
				results = obj.lookup_rdap(depth=1)
				s = StringIO()
				pprint.pprint( results , s )
				out += '\n\n\n'
				out += s.getvalue()


				b_ret = True

			except Exception as e :
				out = e.message



			return b_ret , str( out )
开发者ID:chromatic-universe,项目名称:cci-develop,代码行数:50,代码来源:kc_wireless.py

示例8: _whois

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def _whois(ip, org_names):
    from ipwhois import IPWhois

    if type(ip) is not str:
        ip = _get_flow_ip(ip)

    if ip not in _whois_cache:
        whois = IPWhois(ip)
        try:
            name = whois.lookup_rdap()['network']['name']
            if not name:
                name = whois.lookup()['nets'][0]['name']
        except:
            print("WHOIS ERROR")
            name = 'OTHER'

        _whois_cache[ip] = _clean_netname(org_names, name, ip)
    return _whois_cache[ip]
开发者ID:CacheBrowser,项目名称:cachebrowser,代码行数:20,代码来源:scrambler.py

示例9: test_lookup_rdap

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
    def test_lookup_rdap(self):
        try:
            from urllib.request import ProxyHandler, build_opener
        except ImportError:
            from urllib2 import ProxyHandler, build_opener

        ips = [
            '74.125.225.229',  # ARIN
            '2001:4860:4860::8888',
            '62.239.237.1',  # RIPE
            '2a00:2381:ffff::1',
            '210.107.73.73',  # APNIC
            '2001:240:10c:1::ca20:9d1d',
            '200.57.141.161',  # LACNIC
            '2801:10:c000::',
            '196.11.240.215',  # AFRINIC
            '2001:43f8:7b0::'
        ]

        for ip in ips:

            log.debug('Testing: {0}'.format(ip))
            result = IPWhois(ip)

            try:
                self.assertIsInstance(result.lookup_rdap(), dict)
            except (ASNLookupError, ASNRegistryError, WhoisLookupError,
                    HTTPLookupError):
                pass
            except AssertionError as e:
                raise e
            except Exception as e:
                self.fail('Unexpected exception raised: {0}'.format(e))

        handler = ProxyHandler({'http': 'http://0.0.0.0:80/'})
        opener = build_opener(handler)
        result = IPWhois('74.125.225.229', 0, opener)
        self.assertRaises(HTTPLookupError, result.lookup_rdap)

        log.debug('Testing allow_permutations')
        result = IPWhois('74.125.225.229', timeout=0, allow_permutations=False)
        self.assertRaises(ASNRegistryError, result.lookup_rdap)
开发者ID:grcninja,项目名称:ipwhois,代码行数:44,代码来源:test_ipwhois.py

示例10: run_rdap

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
    def run_rdap(self,ip_address):
        """Perform an RDAP lookup for an IP address. An RDAP lookup object is returned.

        From IPWhois: IPWhois.lookup_rdap() is now the recommended lookup method. RDAP provides
        a far better data structure than legacy WHOIS and REST lookups (previous implementation).
        RDAP queries allow for parsing of contact information and details for users, organizations,
        and groups. RDAP also provides more detailed network information.

        Parameters:
        ip_address  The IP address to use for the RDAP look-up
        """
        try:
            with warnings.catch_warnings():
                # Hide the 'allow_permutations has been deprecated' warning until ipwhois removes it
                warnings.filterwarnings("ignore",category=UserWarning)
                rdapwho = IPWhois(ip_address)
                results = rdapwho.lookup_rdap(depth=1)
            return results
        except Exception as error:
            click.secho("[!] Failed to collect RDAP information for {}!".format(ip_address),fg="red")
            click.secho("L.. Details: {}".format(error),fg="red")
开发者ID:chrismaddalena,项目名称:viper,代码行数:23,代码来源:whois.py

示例11: get_rdap_ip

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def get_rdap_ip(ip):
	es = Elasticsearch()
        does_exist = es.exists(index='rdap', doc_type='ipaddr', id = ip)
        print does_exist
        if does_exist is True:
                status = 200
                print "Found it!"
                get_record = es.get(index='rdap',doc_type='ipaddr', id = ip)
                results = jsonify(get_record['_source'])
	else:
		try:
			obj = IPWhois(ip)
			results_raw = obj.lookup_rdap(depth=1)
			status = 200
			results = jsonify(results_raw)
			es.index(index='rdap', doc_type='ipaddr', id=ip, body=json.dumps(results_raw))
		except Exception as e:
			print e
			results = jsonify({'status': "not_found"}) 
			status = 404
			results = jsonify({'status': "not_found"})
	return results,status
开发者ID:trylinux,项目名称:pyrdap,代码行数:24,代码来源:pyrdap_server.py

示例12: analyze

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
    def analyze(ip):
        links = []

        results = IPWhois(ip.value)
        results = results.lookup_rdap()

        for entity in results['objects']:
            entity = results['objects'][entity]
            if entity['contact']['kind'] != 'individual':
                # Create the company
                company = Company.get_or_create(name=entity['contact']['name'], rdap=entity)
                link = Link.connect(ip, company)
                link.add_history('hosting')
                links.append(link)

                # Link it to every email address referenced
                for email_info in entity['contact']['email']:
                    email = Email.get_or_create(value=email_info['value'])
                    link = Link.connect(company, email)
                    links.append(link)

        return links
开发者ID:carriercomm,项目名称:yeti,代码行数:24,代码来源:network_whois.py

示例13: ip_whois

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def ip_whois(ip):
	obj = IPWhois(ip)
	try:
		results = obj.lookup_rdap(depth=1)
	except:
		results = 'notfound'
		print 'ASN Registry Lookup Failed'
	if results != 'notfound':
		print colored(style.BOLD + '\nWhoIS Report for IP: %s\n' + style.END, 'green') % str(ip)
		print colored(style.BOLD + '--------------- Basic Info ---------------' + style.END, 'blue')
		print 'ASN ID: %s' % results['asn']
		if 'network' in results.keys():
			print 'Org. Name: %s' % results['network']['name']
			print 'CIDR Range: %s' % results['network']['cidr']
			print 'Start Address: %s' % results['network']['start_address']
			print 'Parent Handle: %s' % results['network']['parent_handle']
			print 'Country: %s' % results['network']['country']
		if 'objects' and 'entities' in results.keys():
			print colored(style.BOLD + '\n----------- Per Handle Results -----------' + style.END, 'blue')
			for x in results['entities']:
				print 'Handle: %s' % x
				if 'contact' in results['objects'][x].keys():
					print '\tKind: %s' % results['objects'][x]['contact']['kind']
					if results['objects'][x]['contact']['phone'] is not None:
						for y in results['objects'][x]['contact']['phone']:
							print '\tPhone: %s' % y['value']
					if results['objects'][x]['contact']['title'] is not None:
						print results['objects'][x]['contact']['title']
					if results['objects'][x]['contact']['role'] is not None:
						print results['objects'][x]['contact']['role']
					if results['objects'][x]['contact']['address'] is not None:
						for y in results['objects'][x]['contact']['address']:
							print '\tAddress: %s' % y['value'].replace('\n',',')
					if results['objects'][x]['contact']['email'] is not None:
						for y in results['objects'][x]['contact']['email']:
							print '\tEmail: %s' % y['value']
开发者ID:irivera007,项目名称:datasploit,代码行数:38,代码来源:ip_whois.py

示例14: extractDNS

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def extractDNS(ipaddr):
    obj = IPWhois(ipaddr)
    results = obj.lookup_rdap(depth=1)
    pprint(results)
开发者ID:abhi95,项目名称:DetectingMaliciousWebPages,代码行数:6,代码来源:ips.py

示例15: insert

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_rdap [as 别名]
def insert(input_ip='', update=True, expires=7, depth=1):

    if update:

        try:
            # Only update if older than x days.
            tmp = es.search(
                index='ipwhois_base',
                doc_type='base',
                body={
                    'query': {
                        'bool': {
                            'must': [{
                                'range': {
                                    'updated': {
                                        'gt': 'now-{0}d'.format(expires)
                                    }
                                }
                            }, {
                                'term': {
                                    'query': str(input_ip)
                                }
                            }]
                        }
                    }
                }
            )

            if len(tmp['hits']['hits']) > 0:

                return

        # A generic exception is raised, unfortunately.
        except Exception as e:
            print(e)
            pass

    # Perform the RDAP lookup for the input IP address retriving all entities
    # up to depth.
    result = IPWhois(input_ip)
    ret = result.lookup_rdap(depth=depth)

    tmp_objects = ret['objects'].items()

    for ent_k, ent_v in tmp_objects:

        if update:

            try:

                # Only update if older than 7 days.
                es_tmp = es.search(
                    index='ipwhois_entity',
                    doc_type='entity',
                    body={
                        'query': {
                            'bool': {
                                'must': [
                                    {
                                        'range': {
                                            'updated': {
                                                'gt': 'now-{0}d'.format(expires)
                                            }
                                        }
                                    },
                                    {
                                        'term': {
                                            'handle': str(ent_k)
                                        }
                                    }
                                ]
                            }
                        }
                    }
                )

                if len(es_tmp['hits']['hits']) > 0:

                    continue

            # A generic exception is raised, unfortunately.
            except Exception as e:
                print(e)
                pass

        ent = ent_v

        if sys.version_info >= (2, 7):

            # Iterate the contact addresses.
            for addr_k, addr_v in enumerate(ent_v['contact']['address']):

                try:

                    # Attempt to translate the contact address to geo
                    # coordinates via geopy.
                    location = GEOLOCATOR.geocode(addr_v['value'].replace(
                        '\n', ' '))

                    # Add the geo coordinates for the contact address.
#.........这里部分代码省略.........
开发者ID:secynic,项目名称:ipwhois,代码行数:103,代码来源:elastic_search.py


注:本文中的ipwhois.IPWhois.lookup_rdap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。