本文整理汇总了Python中gevent.socket.gethostbyname方法的典型用法代码示例。如果您正苦于以下问题:Python socket.gethostbyname方法的具体用法?Python socket.gethostbyname怎么用?Python socket.gethostbyname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent.socket
的用法示例。
在下文中一共展示了socket.gethostbyname方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resolve_hostnames
# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import gethostbyname [as 别名]
def resolve_hostnames(hostnames, timeout):
"""
Do DNS resolution for a given list of hostnames
This function uses gevent to resolve all the hostnames in *parallel*
Args:
hostnames (list): A list of strings
timeout (int): The number of seconds to wait for resolution of **all** hostnames
Returns:
list: A list of (hostname, address) tuples in the same order as the input list of hostnames
"""
assert validators.PanoptesValidators.valid_nonempty_iterable_of_strings(hostnames), u'hostnames should be a list'
assert validators.PanoptesValidators.valid_nonzero_integer(timeout), u'timeout should be an int greater than zero'
jobs = [gevent.spawn(wrap_errors(gaierror, socket.gethostbyname), host) for host in hostnames]
gevent.joinall(jobs, timeout=timeout)
addresses = [job.value if not isinstance(job.get(), gaierror) else None for job in jobs]
results = [(hostnames[i], result) for i, result in enumerate(addresses)]
return results
示例2: __init__
# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import gethostbyname [as 别名]
def __init__(self, args, db, host):
self.args = args
self.db = db
self.hostname = host
self.conn = None
self.admin_privs = False
self.logger = None
self.password = ''
self.username = ''
self.kerberos = True if self.args.kerberos else False
self.aesKey = None if not self.args.aesKey else self.args.aesKey
self.kdcHost = None if not self.args.kdcHost else self.args.kdcHost
self.failed_logins = 0
self.local_ip = None
try:
self.host = gethostbyname(self.hostname)
if self.args.kerberos:
self.host = self.hostname
except Exception as e:
logging.debug('Error resolving hostname {}: {}'.format(self.hostname, e))
return
self.proto_flow()
示例3: main
# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import gethostbyname [as 别名]
def main():
urls = ['www.google.com', 'www.example.com', 'www.python.org']
jobs = [gevent.spawn(socket.gethostbyname, url) for url in urls]
gevent.joinall(jobs, timeout=2)
print([job.value for job in jobs])
示例4: parse_address
# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import gethostbyname [as 别名]
def parse_address(address):
try:
hostname, port = address.rsplit(':', 1)
port = int(port)
except ValueError:
sys.exit('Expected HOST:PORT: %r' % address)
return gethostbyname(hostname), port
示例5: resolve
# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import gethostbyname [as 别名]
def resolve(domain):
try:
return({domain: socket.gethostbyname(domain)})
except:
return({domain: "none"})
示例6: init_from_log_file
# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import gethostbyname [as 别名]
def init_from_log_file(self, log_file):
self.reset_scanner()
self.log_file = log_file
self.scheme, self.host, self.path = self._parse_url_from_file()
self.domain_sub = get_domain_sub(self.host)
if self.host:
if self.host.find(':') > 0:
_ret = self.host.split(':')
self.host = _ret[0]
self.port = _ret[1]
elif self.scheme == 'https':
self.port = 443
elif self.scheme == 'http':
self.port = 80
else:
self.port = None
if not is_port_open(self.host, self.port):
self.print_msg('[Port Not Open] %s:%s' % (self.host, self.port))
return False
self.has_http = True
self.no_scripts = 1
self.init_final()
self.load_all_urls_from_log_file()
return True
else:
host = os.path.basename(log_file).replace('.log', '')
try:
socket.gethostbyname(host)
self.init_from_url(host) # Fix Me
return True
except Exception as e:
self.print_msg('[ERROR] Invalid host from log name: %s' % host)
return False
示例7: domain_lookup_check
# 需要导入模块: from gevent import socket [as 别名]
# 或者: from gevent.socket import gethostbyname [as 别名]
def domain_lookup_check(queue_targets_origin, processed_targets, queue_targets, q_results):
"""
解析域名,检查域名有效性
"""
while True:
try:
url = queue_targets_origin.get_nowait()
except Queue.Empty as e:
break
# scheme netloc path
if url.find('://') < 0:
netloc = url[:url.find('/')] if url.find('/') > 0 else url
else:
scheme, netloc, path, params, query, fragment = urlparse.urlparse(url, 'http')
# host port
if netloc.find(':') >= 0:
_ = netloc.split(':')
host = _[0]
else:
host = netloc
try:
ip = g_socket.gethostbyname(host)
processed_targets.append(ip)
queue_targets.put((url, 0))
except Exception as e:
q_results.put('Invalid domain: %s' % host)