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


Python IPWhois.lookup_whois方法代码示例

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


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

示例1: get_whois_ip

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [as 别名]
def get_whois_ip(ip,refresh=None):
	es = Elasticsearch()
	print repr(ip)
	id_num = str(ip).replace(".","0")
	does_exist = es.exists(index='rwhois2', doc_type='ipaddr', id = id_num)
	print does_exist
	if does_exist is True and refresh is None:
		status = 200
		print "Found it!"
		get_record = es.get(index='rwhois2',doc_type='ipaddr', id = id_num)
		results = jsonify(get_record['_source'])
	elif does_exist is True and refresh is not None:
                status = 200
                print "Forcing refresh!"
                es.delete(index='rwhois2', doc_type='ipaddr', id = id_num)
                try:
                        ipwhois.net.socks.setdefaultproxy(ipwhois.net.socks.SOCKS5,"localhost")
			obj = IPWhois(ip)
                        try:
                                results_raw = obj.lookup_whois(get_referral=True,inc_nir=True)
                        except:
                                results_raw = obj.lookup_whois()

                        status = 200
                        results = jsonify(results_raw)
                        es.index(index='rwhois2', doc_type='ipaddr', id=id_num, body=results_raw)

                except Exception as e:
                        print e
                        results = jsonify({'status': "not_found"})
                        status = 404


	
	else:
		try:
			obj = IPWhois(ip)
			try:
				results_raw = obj.lookup_whois(get_referral=True)
			except:
				results_raw = obj.lookup_whois()
			status = 200
			results = jsonify(results_raw)
			id_num = str(ip).replace(".","0")
                        print results
                        try:
				es.index(index='rwhois2', doc_type='ipaddr', id=id_num, body=results_raw)
			except Exception as e:
				print "Elasticsearch encountered a problem ", e
                                pass
		except Exception as e:
                        #print results_raw
        	        print e
                	results_raw = jsonify({'status': "not_found"})
	                status = 404
        	        results = jsonify({'status': "not_found"})
        return results,status
开发者ID:trylinux,项目名称:pyrdap,代码行数:59,代码来源:pyrdap_server.py

示例2: performWhoIs

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [as 别名]
def performWhoIs(IP):
    print()
    print(timeStamp() + "* Performing WHOIS on " + IP)
    obj = IPWhois(IP)
    res = obj.lookup_whois()
    print(timeStamp() + "- WHOIS name: " + res["nets"][0]['name'])
    print(timeStamp() + "- WHOIS CIDR: " + res['asn_cidr'])
    print(timeStamp() + "- More info at http://who.is/whois-ip/ip-address/" + IP)
开发者ID:rascal999,项目名称:qad,代码行数:10,代码来源:__init__.py

示例3: lookup

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [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

示例4: sitebilgilerinibul

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [as 别名]
def sitebilgilerinibul(site):
    ip     = socket.gethostbyname(site)
    obje   = IPWhois(ip)
    obj    = obje.lookup_whois()
    eposta = obj["nets"][0]['emails']
    desc  = obj["nets"][0]['description']
    print  "Site\t: ", site, "\n"
    print "IP adresi\t: ", ip
    print  "\nAçıklama\t: ", desc
    print "\nEmails\t: \n"
    print  email
开发者ID:besimaltnok,项目名称:sitebilgilerinibul,代码行数:13,代码来源:sitebilgilerinibul.py

示例5: add_kvstore

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [as 别名]
    def add_kvstore(self,ips_fin):
        
        i=0
        new_ip=""
        dict_yield_new=[]

        #Ignore Splunk certificate warnings
        requests.packages.urllib3.disable_warnings()

        count =len(ips_fin)-1

        for ip in range(0,count):

            #if its contains CIDR, convert it to an IP address and call WHOIS database

            if (str(ips_fin.keys()[i])).find("/") != -1:

                cidr_string = str(ips_fin.keys()[i])
                new_ip = cidr_string.split("/")[0]

                obj = IPWhois(new_ip)
                results1 = obj.lookup_whois()
                
                kv_data = json.dumps(results1)
                r = requests.post(self.kvURI, kv_data, auth=(self.splunkUser, self.splunkPwd), verify=False, headers=self.headers)
                dict_yield_new.append(results1)
                

            #IF NOT CIDR then call WHOIS
            else:
                

                old_ip=str(ips_fin.keys()[i])
                obj = IPWhois(old_ip)
                results2 = obj.lookup_whois()
                kv_data = json.dumps(results2)
                r = requests.post(self.kvURI, kv_data, auth=(self.splunkUser, self.splunkPwd), verify=False, headers=self.headers)
                dict_yield_new.append(results2)
                #print results2

        return dict_yield_new
开发者ID:patel-bhavin,项目名称:mysplunk_csc,代码行数:43,代码来源:generateblocklist.py

示例6: extract_whois

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [as 别名]
 def extract_whois(self, ip): # extract whois description
     try:
         if re.match(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip): # only IPs
             w = IPWhois(ip, timeout=5) # timeout 5
             res = w.lookup_whois(retry_count=2) # legacy whois / retries 2
             descr = res["nets"][0]['description']
             if self.options.verbose:
                 print"[Verbose] - Resolving:", ip
         else:
             descr = None
     except:
         descr = None
     return descr
开发者ID:epsylon,项目名称:pydog4apache,代码行数:15,代码来源:main.py

示例7: analyze

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

        r = IPWhois(ip.value)
        result = r.lookup_whois()
        results.update(raw=pformat(result))

        # Let's focus on the most specific information
        # Which should be in the smallest subnet
        n = 0
        smallest_subnet = None

        for network in result['nets']:
            cidr_bits = int(network['cidr'].split('/')[1].split(',')[0])
            if cidr_bits > n:
                n = cidr_bits
                smallest_subnet = network

        if smallest_subnet:
            # Create the company
            company = Company.get_or_create(
                name=smallest_subnet['description'].split("\n")[0])
            links.update(ip.active_link_to(company, 'hosting', 'Network Whois'))

            # Link it to every email address referenced
            if smallest_subnet['emails']:
                for email_address in smallest_subnet['emails']:
                    email = Email.get_or_create(value=email_address)
                    links.update(company.link_to(email, None, 'Network Whois'))

            # Copy the subnet info into the main dict
            for key in smallest_subnet:
                if smallest_subnet[key]:
                    result["net_{}".format(key)] = smallest_subnet[key]

        # Add the network whois to the context if not already present
        for context in ip.context:
            if context['source'] == 'network_whois':
                break
        else:
            # Remove the nets info (the main one was copied)
            result.pop("nets", None)
            result.pop("raw", None)
            result.pop("raw_referral", None)
            result.pop("referral", None)
            result.pop("query", None)

            result['source'] = 'network_whois'
            ip.add_context(result)

        return list(links)
开发者ID:raymundl,项目名称:yeti,代码行数:53,代码来源:network_whois.py

示例8: gather

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [as 别名]
    def gather(self, all_ips):

        for path, incoming_ip_obj in all_ips.iteritems():

            if incoming_ip_obj[0].ip_whois == "" and incoming_ip_obj[0].ip_address != "":

                try:
                    print "Gathering whois information about " + incoming_ip_obj[0].ip_address
                    ip_whois = IPWhois(incoming_ip_obj[0].ip_address)
                    incoming_ip_obj[0].ip_whois = ip_whois.lookup_whois()
                except IPDefinedError:
                    print helpers.color("[*] Error: Private IP address, skipping IP!", warning=True)
                except HTTPLookupError:
                    print helpers.color("Could not connect online to lookup whois for " + incoming_ip_obj[0].domain_name, warning=True)
        return
开发者ID:ChrisTruncer,项目名称:Just-Metadata,代码行数:17,代码来源:whois_info.py

示例9: analysis

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [as 别名]
def analysis(ip):
    target = open("netname.txt", 'a')
    obj = IPWhois(ip.network)
    res = obj.lookup_whois()
    result = res['nets'][0]
    # kiem tra inetnum co trong ban ghi khong
    if 'range' in result:
        if check(result['range']):
            if "\n" in result['description']:
                description_ = result['description'].split('\n')
                target.write("description:  %s %s\n" % (description_[0], description_[-1]))
            else:
                target.write("description:  %s\n" % (result['description']))
            target.write("inetnum:      %s\n" % (result['range']))
            target.write("netname:      %s\n" % (result['name']))
            target.write("cidr:         %s\n" % (result['cidr']))
            target.write("------------------------------------------"
                         "----------------------------------------\n")
            return result['cidr'].split('/')[-1]
    target.close()
开发者ID:quangns,项目名称:test,代码行数:22,代码来源:netname.py

示例10: who

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [as 别名]
 def who(self, ip):
     try:
         obj = IPWhois(ip)
         results = obj.lookup_whois()
         if 'nets' in results:
             name=desc=cidr=iprange=''
             if 'name' in results['nets'][0]:
                 name = results['nets'][0]['name']
             if 'description' in results['nets'][0]:
                 desc = results['nets'][0]['description']
                 if desc:
                     desc = desc.replace("\n",",")    
             if 'cidr' in results['nets'][0]:
                 cidr = results['nets'][0]['cidr']
             if 'range' in results['nets'][0]:
                 iprange = results['nets'][0]['range']
                 d = {'Name': name, 'Description': desc, 'CIDR': cidr, 'IPRange': iprange}
             self._add_result('Whois Info:', ip, d)
             
     except Exception as e:
         self._error("Error getting WHOIS report from X-Force Exchange: {0}".format(str(e)))
开发者ID:TheDr1ver,项目名称:crits_services,代码行数:23,代码来源:__init__.py

示例11: IPWhois

# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup_whois [as 别名]
import requests
from ipwhois import IPWhois

r = requests.get('http://ipv4.icanhazip.com')

ip = r.text

ip = ip.rstrip()
obj = IPWhois(ip)
results = obj.lookup_whois()
print "sensorIP="+str(ip)+", ASN="+str(results['asn'])+", ASN_Country="+str(results['asn_country_code'])+", description="+str(results['nets'][0]['description']) + ", network_name="+str(results['nets'][0]['name'])+", network_range="+str(results['nets'][0]['range'])
开发者ID:marclaliberte,项目名称:Tango,代码行数:13,代码来源:input.py


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