本文整理汇总了Python中ipwhois.IPWhois方法的典型用法代码示例。如果您正苦于以下问题:Python ipwhois.IPWhois方法的具体用法?Python ipwhois.IPWhois怎么用?Python ipwhois.IPWhois使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipwhois
的用法示例。
在下文中一共展示了ipwhois.IPWhois方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _whois
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [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]
示例2: get_json
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def get_json(self):
obj = ipwhois.IPWhois(self.kwargs["target"])
try:
# import json
# print(json.dumps(obj.lookup_rdap(depth=2)))
# return obj.lookup_rdap(depth=2)
return obj.lookup_rws()
except AttributeError:
# rdap = obj.lookup_rdap(inc_raw=True)
# print(json.dumps(rdap))
# rdap["network"]["range"] = "{start_address} - {end_address}".format(**rdap["network"])
# rdap["network"]["cidr"] = self.get_cidr(rdap["network"])
# return rdap
# RDAP is a stupid format, use raw whois
raw = obj.lookup()
print(raw)
return raw
示例3: whois_ip
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def whois_ip(ip):
# Default to not found
cidr, ranges = "CIDR not found", "Range not found"
# Get whois for IP. Returns a list with dictionary
ip_dict = IPWhois(ip).lookup_rws()
if ip_dict['nets'][0].get('cidr'):
cidr = ip_dict['nets'][0].get('cidr')
if ip_dict['nets'][0].get('range'):
ranges = ip_dict['nets'][0].get('range')
sleep(2)
return cidr, ranges
示例4: get_address_info
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def get_address_info(self, routers):
"""
Get country code and ASN description based on the routers IP address.
:param routers:
:return:
"""
for router in routers:
if isinstance(router, self.__class__.router_cls):
try:
whois = IPWhois(router.address)
results = whois.lookup_rdap(depth=1)
if results['asn_country_code']:
router.country = results['asn_country_code']
if results['asn_description']:
router.asn_description = results['asn_description']
except:
pass
示例5: ip
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def ip(self):
whois_data = IPWhois(self.artifact['name'])
try:
data = whois_data.lookup_whois()
if data is not None:
self.artifact['data']['whois'] = {}
# collect ASN information
self.artifact['data']['whois']['asn'] = data['asn']
self.artifact['data']['whois']['asn']['cidr'] = data['asn_cidr']
self.artifact['data']['whois']['asn']['description'] = data['asn_description']
self.artifact['data']['whois']['asn']['country'] = data['asn_country_code']
if 'nets' in data.keys() and len(data['nets']) > 0:
net_data = data['nets'][0]
self.artifact['data']['whois']['address'] = net_data['address']
self.artifact['data']['whois']['state'] = net_data['state']
self.artifact['data']['whois']['emails'] = net_data['emails']
except Exception as err:
warning('Caught unhandled exception: %s' % str(err))
示例6: get_asn2
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def get_asn2(data):
# find as number with ipwhois modules
if chk_domain(data):
ip, c_name = retIP(data)
if chk_ip(data):
ip = data
obj = IPWhois(ip)
results = obj.lookup()
as_number = 0
subnet = ''
try:
if results.has_key('asn'):
as_number = int(results['asn'])
except:
pass
if results.has_key('asn_cidr'):
subnet = results['asn_cidr']
return as_number, subnet
示例7: get_ip_dict
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def get_ip_dict(self, ip, method='whois'):
''' Get the ip lookup dictionary '''
if not ipwhois:
raise ImportError('Cannot look up ips. You do not have the ipwhois package installed!')
assert method in ['whois', 'rdap'], 'Method must either be rdap or whois'
ipwho = ipwhois.IPWhois(ip)
self.ipmethod = method
ipdict = None
if method == 'whois':
try:
ipdict = ipwho.lookup_whois()
except Exception as e:
print('Could not lookup ip {0}: {1}'.format(ip, e))
elif method == 'rdap':
try:
ipdict = ipwho.lookup_rdap()
except Exception as e:
print('Could not lookup ip {0}: {1}'.format(ip, e))
return ipdict
示例8: whois_lookup
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def whois_lookup(ip):
"""Perform Whois lookup for a given IP
:ip: Ip to peform whois lookup
"""
colors.info('Performing WHOIS lookup')
obj = IPWhois(ip)
response = obj.lookup_whois()
details = response['nets'][0]
name = details['name']
city = details['city']
state = details['state']
country = details['country']
address = details['address']
description = details['description']
return {'Name': name, 'City': city, 'State': state,
'Country': country, 'address': address, 'description': description}
示例9: get_whois_registry_info
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def get_whois_registry_info(ip_input):
"""Gather registry information
Arguments:
ip_input {string} -- Artifact.value
Returns:
{object} -- Contains all registry information
"""
try:
internet_protocol_address_object = IPWhois(ip_input,allow_permutations=True)
try:
whois_response = internet_protocol_address_object.lookup_whois()
if internet_protocol_address_object.dns_zone:
whois_response["dns_zone"] = internet_protocol_address_object.dns_zone
return whois_response
except exceptions.ASNRegistryError as e:
logging.error(traceback.format_exc())
except:
logging.error(traceback.format_exc())
示例10: get_rdap_registry_info
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def get_rdap_registry_info(ip_input, rdap_depth):
"""Gathers registry info in RDAP protocol
Arguments:
ip_input {string} -- Artifact.value
rdap_depth {int} -- 0,1 or 2
Returns:
{object} -- Registry info, RDAP Protocol
"""
try:
internet_protocol_address_object = IPWhois(ip_input,allow_permutations=True)
try:
rdap_response = internet_protocol_address_object.lookup_rdap(rdap_depth)
if internet_protocol_address_object.dns_zone:
rdap_response["dns_zone"] = internet_protocol_address_object.dns_zone
return rdap_response
except exceptions.ASNRegistryError as e:
logging.error(traceback.format_exc())
except:
logging.error(traceback.format_exc())
示例11: deepConnectionLens
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def deepConnectionLens(self, response):
mIP = 'not-found'
mISP = 'not-found'
if response.status_code == 200:
try:
mIP = list(response.raw._connection.sock.getpeername())[0]
mISP = IPWhois(mIP).lookup_whois()['nets'][0]['name']
except AttributeError:
try:
mIP = list(response.raw._connection.sock.socket.getpeername())[0]
mISP = IPWhois(mIP).lookup_whois()['nets'][0]['name']
except AttributeError:
pass
if mIP == 'not-found':
self._iterator.write(f"[x] There's problem when getting icon for {response.url.split('/')[2]} with status code: {response.status_code}" )
return {
'mIP': mIP,
'mISP': mISP
}
示例12: describe_cidr
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def describe_cidr(cidr):
import ipwhois, ipaddress, socket
address = ipaddress.ip_network(str(cidr)).network_address
try:
whois = ipwhois.IPWhois(address).lookup_rdap()
whois_names = [whois["asn_country_code"]] if "asn_country_code" in whois else []
whois_names += [o.get("contact", {}).get("name", "") for o in whois.get("objects", {}).values()]
except Exception:
try:
whois_names = [socket.gethostbyaddr(address)]
except Exception:
whois_names = [cidr]
return ", ".join(str(n) for n in whois_names)
示例13: whois
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def whois(url):
"""Get WHOIS from IP address or hostname.
Args:
url (str): IP address or hostname.
Returns:
dict: Return a JSON object with the WHOIS.
"""
url = url.strip()
if not parse.urlparse(url).scheme:
url = 'http://' + url
host = parse.urlparse(url).netloc
try:
ipaddress.ip_address(host)
ip = host
except Exception:
try:
ips = resolver.query(host, 'A')
ip = ips[0]
except Exception:
return {}
obj = IPWhois(ip)
return obj.lookup_whois()
示例14: run
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def run(self, domain, start_time=""):
""" str, str -> networkx multiDiGraph
:param domain: a string containing a domain to look up
:param start_time: string in ISO 8601 combined date and time format (e.g. 2014-11-01T10:34Z) or datetime object.
:return: a networkx graph representing the whois information about the domain
"""
ip = socket.gethostbyname(domain) # This has a habit of failing
record = [None] * 10
obj = IPWhois(ip)
results = obj.lookup()
nets = results.pop("nets")
for i in range(len(nets)):
net = nets[i]
record[0] = i
if "updated" in net:
record[1] = net['updated'][:10]
elif "created" in net:
record[1] = net['created'][:10]
record[2] = domain
if "name" in net:
record[3] = net['name']
if "organization" in net:
record[4] = net['organization']
if 'address' in net:
record[5] = net['address']
if 'city' in net:
record[6] = net['city']
if 'state' in net:
record[7] = net['state']
if 'country' in net:
record[8] = net['country']
if 'misc_emails' in net and net['misc_emails'] is not None:
emails = net['misc_emails'].split("\n")
record[9] = emails[0]
return self.enrich_record(record, start_time)
示例15: whois_info_fetch
# 需要导入模块: import ipwhois [as 别名]
# 或者: from ipwhois import IPWhois [as 别名]
def whois_info_fetch(self, ip, ips):
for i in ips:
if "whois" not in self.communication_details[ip]["ip_details"][i]:
self.communication_details[ip]["ip_details"][i]["whois"] = ""
try:
whois_info = ipwhois.IPWhois(ip).lookup_rdap()
except:
whois_info = "NoWhoIsInfo"
self.communication_details[ip]["ip_details"][i]["whois"] = whois_info