本文整理汇总了Python中ipwhois.IPWhois.lookup方法的典型用法代码示例。如果您正苦于以下问题:Python IPWhois.lookup方法的具体用法?Python IPWhois.lookup怎么用?Python IPWhois.lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipwhois.IPWhois
的用法示例。
在下文中一共展示了IPWhois.lookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: orgGroups
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def orgGroups(self, sender, mID):
# import pdb; pdb.set_trace()
try:
newmID = "www." + mID
afterAT = "www." + sender[sender.index("@")+1:]
if newmID in self.domainCompanyPairing.keys():
res1 = self.domainCompanyPairing[newmID]
else:
ip1 = socket.gethostbyname(newmID)
obj1 = IPWhois(ip1)
res1 = obj1.lookup(get_referral=True)['nets'][0]['name']
self.domainCompanyPairing[newmID] = res1
if afterAT in self.domainCompanyPairing.keys():
res2 = self.domainCompanyPairing[afterAT]
else:
ip2 = socket.gethostbyname(afterAT)
obj2 = IPWhois(ip2)
res2 = obj2.lookup(get_referral=True)['nets'][0]['name']
self.domainCompanyPairing[afterAT] = res2
if res1 == res2:
return True
return False
except:
return False
示例2: getCIDR
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def getCIDR(cls, ip):
if Lookup.offline:
Lookup.cidr_tot += 1
for cidr in Lookup.seen_pairings_keys:
ip_bin = getBinaryRep(ip, cidr)
if ip_bin in Lookup.seen_pairings[cidr]:
Lookup.cidr_hit += 1
return ip_bin
return getBinaryRep(ip, 32)
else:
Lookup.cidr_tot += 1
try:
if ip in Lookup.seen_pairings:
Lookup.cidr_hit += 1
return Lookup.seen_pairings[ip]
else:
obj = IPWhois(ip)
results = obj.lookup()
if "nets" not in results.keys() or "cidr" not in results["nets"][0].keys():
cidr = ip + "/32"
else:
cidr = results["nets"][0]["cidr"]
Lookup.seen_pairings[ip] = cidr
if cidr:
Lookup.cidr_hit += 1
return cidr
except:
Lookup.seen_pairings[ip] = "Invalid"
return "Invalid"
示例3: test_lookup
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def test_lookup(self):
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:
result = IPWhois(ip)
try:
self.assertIsInstance(result.lookup(), dict)
except (ASNLookupError, ASNRegistryError, WhoisLookupError):
pass
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: %r' % e)
示例4: check_addr_type
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def check_addr_type(addr, addr_dict):
if addr != local and not any([pattern.match(addr) for pattern in pattern_list]):
obj = IPWhois(addr)
results = obj.lookup()
domain = results['nets'][0]['name']
if domain is not None:
addr_dict[addr] = domain
示例5: set
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def set(self,pagenum,kw):
try:
url = 'http://www.ebay.com/sch/i.html?_from=R40&_sacat=0&LH_Complete=1&LH_Sold=1&LH_ItemCondition=3&_nkw=' + kw + '&_pgn=' + str(pagenum) + '&_ipg=200&rt=nc&_dmd=1'
if len(self.proxies) > 0:
countries = get_countries()
obj = IPWhois(self.proxies[0].split(':')[0])
results = obj.lookup(False)
if countries[results['nets'][0]['country']] == "United States":
if self.getfile(url,self.proxies[0],".ht") == "error":
print("Switching Proxy")
self.proxies.pop(0)
self.set(pagenum,kw)
else:
print(self.proxies[0])
else:
print(countries[results['nets'][0]['country']])
print("Non-US IP " + self.proxies[0].split(':')[0] + ": Switching Proxy")
self.proxies.pop(0)
self.set(pagenum,kw)
else:
print("No Proxies in Queue")
except Exception as e:
print(str(e))
示例6: whois
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def whois(ip):
try:
obj = IPWhois(ip)
response = obj.lookup()
except ipwhois.exceptions.WhoisLookupError:
return None
return response
示例7: geoinfo
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def geoinfo(self):
try:
data = IPWhois(self.ip)
return data.lookup(False)['nets'][0]
except:
#raise
return None
示例8: getIPandWhoIsData
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def getIPandWhoIsData(self,url):
try:
ip=socket.gethostbyname(url);
obj=IPWhois(ip);
whoIsDict=obj.lookup();
whoIsDict['resolved_IP']=ip;
return {url : whoIsDict};
except Exception:
return dict();
示例9: queryIP
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def queryIP(self,ip):
try:
self.result['type'] = 'ip'
self.result['keyword'] = ip
self.ip = ip
ipwhois = IPWhois(self.ip)
self.result['whois'] = ipwhois.lookup()
except Exception as e:
self.result['exceptions'].append(e)
return self
示例10: test_lookup
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def test_lookup(self):
result = IPWhois('74.125.225.229')
try:
self.assertIsInstance(result.lookup(), dict)
except (ASNLookupError, WhoisLookupError):
pass
except AssertionError as e:
raise e
except Exception as e:
self.fail('Unexpected exception raised: %r' % e)
示例11: resolveDomainIpwhois
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def resolveDomainIpwhois(dom):
print "... ipwhois"
i = 0
while(i < len(dom['ipaddr'])):
time.sleep(1)
ip_whois = IPWhois( dom['ipaddr'][i]['ipaddr'] )
dom['ipaddr'][i]['whois'] = ip_whois.lookup()
pprint(dom['ipaddr'][i]['whois'])
i += 1
示例12: run
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def run(self):
try:
ip_whois = IPWhois(self._dst_ip)
raw_res = ip_whois.lookup()
res = []
for k,v in raw_res.iteritems():
if not v is None:
res.append("%s: %s" % (k,v))
return ",".join(res)
except Exception, e:
return ""
示例13: check_site_hosting
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def check_site_hosting(url):
urlbreakdown = urlparse.urlparse(url);
netlocation = urlbreakdown.netloc;
#urlcentre = url.split("://")[1].strip("/");
if netlocation[-12:] == "crowdmap.com":
owner = "crowdmap"
else:
ipaddress = socket.gethostbyname(netlocation);
#response = os.system("ping -c 1 " + ipaddress); #0 = site's up and okay
obj = IPWhois(ipaddress);
res=obj.lookup();
owner = res['nets'][0]['description'];
return(owner)
示例14: gather
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def gather(self, all_ips):
for path, incoming_ip_obj in all_ips.iteritems():
if incoming_ip_obj[0].ip_whois == "":
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()
except IPDefinedError:
print helpers.color("[*] Error: Private IP address, skipping IP!", warning=True)
return
示例15: analyze
# 需要导入模块: from ipwhois import IPWhois [as 别名]
# 或者: from ipwhois.IPWhois import lookup [as 别名]
def analyze(ip, results):
links = set()
r = IPWhois(ip.value)
result = r.lookup()
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'].split("\n"):
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)