本文整理汇总了Python中socket.gethostbyname_ex函数的典型用法代码示例。如果您正苦于以下问题:Python gethostbyname_ex函数的具体用法?Python gethostbyname_ex怎么用?Python gethostbyname_ex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gethostbyname_ex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: connection
def connection(self, list, module):
print("bla")
for i in range(len(list)):
for i in range(len(self.addresses)):
address = socket.gethostbyname_ex(self.addresses[i][1])
if list[i][1][0] == address[2][0]:
return list[i][0]
for i in range(len(self.addresses)):
print("searching")
print(self.addresses[i])
if(self.addresses[i][0] == module):
while 1:
try:
print("adres gevonden")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.addresses[i][1], int(self.addresses[i][2])))
address = socket.gethostbyname_ex(self.addresses[i][1])
list.append((s, (address[2][0], int(self.addresses[i][2]))))
return s
except EnvironmentError as exc:
if exc.errno == errno.ECONNREFUSED:
print 'trying again in 10 seconds\n\r'
time.sleep(10)
else:
raise
else:
break
开发者ID:tamsl,项目名称:swe-thaf,代码行数:27,代码来源:communicator.py
示例2: get_remote_machine_info
def get_remote_machine_info():
remote_host = 'www.079l.com'
try:
print "IP address: %s" % socket.gethostbyname(remote_host)
print socket.gethostbyname_ex(remote_host)
except socket.error, err_msg:
print "%s: %s" % (remote_host, err_msg)
开发者ID:zengqiu,项目名称:study,代码行数:7,代码来源:remote_machine_info.py
示例3: getmachinetype
def getmachinetype():
#print "running on host ",myhost
if myhost.startswith('dvrubu-') or myhost.startswith('dvfu-') : return 'daq2val','fu'
elif myhost.startswith('dvbu-') : return 'daq2val','bu'
elif myhost.startswith('fu-') : return 'daq2','fu'
elif myhost.startswith('hilton-') : return 'hilton','fu'
elif myhost.startswith('bu-') : return 'daq2','bu'
elif myhost.startswith('srv-') or myhost.startswith('ncsrv-'):
try:
es_cdaq_list_ip = socket.gethostbyname_ex('es-cdaq')[2]
es_tribe_list_ip = socket.gethostbyname_ex('es-tribe')[2]
for es in es_cdaq_list:
try:
es_cdaq_list_ip.append(socket.gethostbyname_ex(es)[2][0])
except Exception as ex:
print ex
for es in es_tribe_list:
try:
es_tribe_list_ip.append(socket.gethostbyname_ex(es)[2][0])
except Exception as ex:
print ex
myaddr = socket.gethostbyname(myhost)
if myaddr in es_cdaq_list_ip:
return 'es','escdaq'
elif myaddr in es_tribe_list_ip:
return 'es','tribe'
else:
return 'unknown','unknown'
except socket.gaierror, ex:
print 'dns lookup error ',str(ex)
raise ex
开发者ID:diguida,项目名称:hltd,代码行数:33,代码来源:setupmachine.py
示例4: test_gethostbyname_ex
def test_gethostbyname_ex():
# 查看服务器更详细的信息
host = 'www.baidu.com'
try:
print socket.gethostbyname_ex(host)
except socket.error:
pass
开发者ID:ilib0x00000000,项目名称:NULL,代码行数:7,代码来源:py_socket_base.py
示例5: hostInfo
def hostInfo():
hostName = socket.gethostname()
print hostName
print socket.gethostbyname(hostName)
print socket.gethostbyname_ex(hostName)
print socket.getfqdn(hostName)
print socket.getaddrinfo("www.baidu.com", 80)
开发者ID:empljx,项目名称:pyutil,代码行数:7,代码来源:socketUtil.py
示例6: connectRecv
def connectRecv(port, networkNum, timeout):
# configuration parameters; purpose unknown
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
# if networkNum = 0, connect to relay stations on LAN, if networkNum = 1, connect on Wi-Fi
try:
name = socket.gethostbyname_ex(socket.gethostname())[-1][networkNum]
except:
name = socket.gethostbyname_ex(socket.gethostname())[-1][1-networkNum]
server_address = (name, port)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
sock.settimeout(timeout)
# Listen for incoming connections
sock.listen(1)
# Wait for a connection
print >>sys.stderr, 'waiting for a connection'
try:
connection, client_address = sock.accept()
except:
return None
print >>sys.stderr, 'connection from', client_address
# make connection nonblocking
connection.settimeout(0)
return connection
开发者ID:jed4h,项目名称:BESI_Basestation,代码行数:32,代码来源:streamUtils.py
示例7: Open
def Open(self, timeout):
if self.socket:
return
if self.port <= 0:
# Create an Unix Data Socket instead of a
# normal TCP socket
try:
socktype = socket.AF_UNIX
except AttributeError:
logging.error('The system does not support ' +
'Unix Domain Sockets')
raise
sockaddr = self.address
else:
# Create a TCP socket
socktype = socket.AF_INET
sockaddr = (self.address, self.port)
# Validate address
try:
socket.gethostbyname_ex(self.address)
except:
logging.error('Could not resolve address for host ' +
self.address)
raise
self.socket = socket.socket(socktype, socket.SOCK_STREAM)
self.socket.settimeout(timeout)
self.socket.connect(sockaddr)
开发者ID:hpg-cepetro,项目名称:spitz,代码行数:30,代码来源:SimpleEndpoint.py
示例8: __init__
def __init__(self):
self.closeAll = False
try:
self.host = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][1] #arrumar para todos pcs try except
except:
self.host = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][0] #pega o IP da máquina
self.port = 80 #a porta da conexão é a porta 80 web (sempre aberta, não precisa)
开发者ID:lucasfontenla,项目名称:Projeto_Final_CaboDeGuerra,代码行数:7,代码来源:gameServer2.py
示例9: __setitem__
def __setitem__(self, key, value):
if key == "Stack":
self.set_stack(value)
elif key == "node-limit":
self.data[key] = value
self.filter_nodes()
elif key == "nodes":
self.Nodes = []
for node in value:
# I don't think I need the IP address, etc. but this validates
# the node name against /etc/hosts and/or DNS, so it's a
# GoodThing(tm).
try:
n = node.strip()
if self.data["docker"] == 0:
socket.gethostbyname_ex(n)
self.Nodes.append(n)
except:
self.logger.log(node+" not found in DNS... aborting")
raise
self.filter_nodes()
else:
self.data[key] = value
开发者ID:gao-yan,项目名称:pacemaker,代码行数:28,代码来源:environment.py
示例10: handleEvent
def handleEvent(self, event):
eventName = event.eventType
srcModuleName = event.module
eventData = event.data
addrs = None
sf.debug("Received event, " + eventName + ", from " + srcModuleName)
# Don't look up stuff twice
if self.results.has_key(eventData):
sf.debug("Skipping " + eventData + " as already resolved.")
return None
else:
self.results[eventData] = True
try:
if eventName != 'IP_ADDRESS':
if '://' in eventData:
addrs = socket.gethostbyname_ex(sf.urlFQDN(eventData))
else:
addrs = socket.gethostbyname_ex(eventData)
else:
addrs = socket.gethostbyaddr(eventData)
except socket.error as e:
sf.info("Unable to resolve " + eventData)
return None
for addr in addrs:
if type(addr) == list:
for host in addr:
self.processHost(host, event)
else:
self.processHost(addr, event)
return None
开发者ID:jspc,项目名称:spiderfoot,代码行数:35,代码来源:sfp_dns.py
示例11: test
def test(self):
# We need the version for this
try:
socket.gethostbyname_ex(self.server)[2][0]
except socket.gaierror as e:
raise_from(TransportError("Server '%s' does not exist" % self.server), e)
return test_credentials(protocol=self)
开发者ID:SamCB,项目名称:exchangelib,代码行数:7,代码来源:protocol.py
示例12: get_source_domain_of_target_sqli_urls
def get_source_domain_of_target_sqli_urls(url):
import socket
import re
sqli_url_domain=re.sub(r'(https://)|(http://)|(\s)|(/.*)|(:.*)',"",url)
#print sqli_url_domain
f=open("targets.txt","r+")
targets_list=f.readlines()
f.close()
all_list=[]
for each in targets_list:
each=re.sub(r'(https://)|(http://)|(\s)|(/.*)|(:.*)',"",each)
domain=[]
domain.append(each)
try:
all_nics_ip=socket.gethostbyname_ex(each)[2]
each_list=all_nics_ip+domain
all_list.append(each_list)
except:
pass
#print all_list
for single_list in all_list:
try:
sqli_url_ip=socket.gethostbyname_ex(sqli_url_domain)[2]
#print sqli_url_ip
#print 55555555
#print single_list
if sqli_url_ip[0] in single_list:
#print 66666666
#print single_list[-1]
return single_list[-1]
except:
pass
开发者ID:0x24bin,项目名称:MyToolKit,代码行数:33,代码来源:mail.py
示例13: _load_ips
def _load_ips():
"""load the IPs that point to this machine
This function will only ever be called once.
"""
global LOCALHOST
try:
LOCAL_IPS[:] = socket.gethostbyname_ex('localhost')[2]
except socket.error:
pass
try:
hostname = socket.gethostname()
PUBLIC_IPS[:] = socket.gethostbyname_ex(hostname)[2]
# try hostname.local, in case hostname has been short-circuited to loopback
if not hostname.endswith('.local') and all(ip.startswith('127') for ip in PUBLIC_IPS):
PUBLIC_IPS[:] = socket.gethostbyname_ex(socket.gethostname() + '.local')[2]
except socket.error:
pass
finally:
PUBLIC_IPS[:] = uniq_stable(PUBLIC_IPS)
LOCAL_IPS.extend(PUBLIC_IPS)
# include all-interface aliases: 0.0.0.0 and ''
LOCAL_IPS.extend(['0.0.0.0', ''])
LOCAL_IPS[:] = uniq_stable(LOCAL_IPS)
LOCALHOST = LOCAL_IPS[0]
开发者ID:AlfiyaZi,项目名称:ipython,代码行数:29,代码来源:localinterfaces.py
示例14: _load_ips_gethostbyname
def _load_ips_gethostbyname():
"""load ip addresses with socket.gethostbyname_ex
This can be slow.
"""
global LOCALHOST
try:
LOCAL_IPS[:] = socket.gethostbyname_ex('localhost')[2]
except socket.error:
# assume common default
LOCAL_IPS[:] = ['127.0.0.1']
try:
hostname = socket.gethostname()
PUBLIC_IPS[:] = socket.gethostbyname_ex(hostname)[2]
# try hostname.local, in case hostname has been short-circuited to
# loopback
if not hostname.endswith('.local') and all(ip.startswith('127') for ip in PUBLIC_IPS):
PUBLIC_IPS[:] = socket.gethostbyname_ex(
socket.gethostname() + '.local')[2]
except socket.error:
pass
finally:
PUBLIC_IPS[:] = uniq_stable(PUBLIC_IPS)
LOCAL_IPS.extend(PUBLIC_IPS)
# include all-interface aliases: 0.0.0.0 and ''
LOCAL_IPS.extend(['0.0.0.0', ''])
LOCAL_IPS[:] = uniq_stable(LOCAL_IPS)
LOCALHOST = LOCAL_IPS[0]
开发者ID:pyarnold,项目名称:ipython,代码行数:32,代码来源:localinterfaces.py
示例15: getmachinetype
def getmachinetype():
#print "running on host ",myhost
if myhost.startswith('ncsrv-'):
try:
es_cdaq_list_ip = socket.gethostbyname_ex('es-cdaq')[2]
es_local_list_ip = socket.gethostbyname_ex('es-local')[2]
for es in es_cdaq_list:
try:
es_cdaq_list_ip.append(socket.gethostbyname_ex(es)[2][0])
except Exception as ex:
print ex
for es in es_local_list:
try:
es_local_list_ip.append(socket.gethostbyname_ex(es)[2][0])
except Exception as ex:
print ex
myaddr = socket.gethostbyname(myhost)
if myaddr in es_cdaq_list_ip:
return 'es','escdaq','prod'
elif myaddr in es_local_list_ip:
return 'es','eslocal','prod'
else:
return 'unknown','unknown'
except socket.gaierror, ex:
print 'dns lookup error ',str(ex)
raise ex
开发者ID:cmsdaq,项目名称:runriver,代码行数:28,代码来源:essetupmachine.py
示例16: new_site
def new_site(domain_name):
if request.method == 'GET':
top_nav = get_top_nav()
domain = Domain.get(domain_name)
if domain:
if domain.website_status == "complete": return redirect(domain.url)
else:
try:
domain_name = utils.sanitize_domain_name(domain_name)
socket.gethostbyname_ex(domain_name)
domain = Domain.objects.create(domain_name=domain_name)
except:
return render_template('domain/not_existing.html', **locals())
panno_mascot = '/static/img/panno_mascot/HomePage.png'
return render_template('domain/new_site.html', **locals())
else:
domain = Domain.get(domain_name, create=True)
if domain and domain.website_status == "complete": return redirect(domain.url)
response = make_response(redirect("/subscribe/%s" % domain.name))
response.set_cookie("subscription_email", request.form.get("email", ""))
return response
开发者ID:marqui678,项目名称:finalchance.Panopta,代码行数:25,代码来源:website.py
示例17: __validate_cookie
def __validate_cookie(self, name, param):
try:
(ipv4, port) = f5bigip_decode(param)
socket.gethostbyname_ex(ipv4)
return True
except Exception as e:
print e.message
return False
开发者ID:skylazart,项目名称:pythonscripts,代码行数:8,代码来源:f5bigip_enum.py
示例18: validate_whitelist
def validate_whitelist(self):
"""Make sure ip's and domain name can be resolved."""
for addr in self.whitelist:
try:
socket.gethostbyname_ex(addr)
except:
raise APIException("'{}' does not look like an ip or domain name".format(addr), 400)
开发者ID:waltermoreira,项目名称:adama,代码行数:8,代码来源:adapter.py
示例19: get_names
def get_names(self):
if FileHandler.names is None:
try:
FileHandler.names = tuple(socket.gethostbyname_ex('localhost')[2] + socket.gethostbyname_ex(socket.gethostname())[2])
except socket.gaierror:
FileHandler.names = (socket.gethostbyname('localhost'),)
return FileHandler.names
开发者ID:webiumsk,项目名称:WOT-0.9.15-CT,代码行数:8,代码来源:urllib2.py
示例20: is_valid_dns
def is_valid_dns(name, dns, **kwargs):
"""Valid the format of DNS."""
if is_valid_ip(dns):
return True
try:
socket.gethostbyname_ex(dns)
except Exception:
return False
return True
开发者ID:naniid,项目名称:compass-core,代码行数:9,代码来源:validator.py
注:本文中的socket.gethostbyname_ex函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论