本文整理汇总了Python中socket.gethostbyname_ex方法的典型用法代码示例。如果您正苦于以下问题:Python socket.gethostbyname_ex方法的具体用法?Python socket.gethostbyname_ex怎么用?Python socket.gethostbyname_ex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket
的用法示例。
在下文中一共展示了socket.gethostbyname_ex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_cf_domain
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def get_cf_domain(domain,cf_ranges):
if domain.endswith('cloudfront.net'):
return False
domain_ips = []
try:
domain_ips = socket.gethostbyname_ex(domain)[2]
except:
pass
for ip in domain_ips:
for ip_range in cf_ranges:
ip_network = IPNetwork(ip_range)
if ip in ip_network:
print(' [+] Found CloudFront domain --> ' + str(domain))
return True
return False
# test domains for CloudFront misconfigurations
示例2: get_ip_address
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def get_ip_address():
if platform.system() == "Windows":
import socket
ipList = socket.gethostbyname_ex(socket.gethostname())
j = 0
print "Index | IP"
for i in ipList[2]:
print j, " ",i
j = j + 1
index = int(raw_input("Please input the index number of you IP address.(Usually, the IP looks like 10.xxx.xxx.xxx):\n"))
if index >= 0 and index < len(ipList[2]):
return ipList[2][index]
else:
print "Invalid Index number"
exit()
ip=os.popen(". /lib/functions/network.sh; network_get_ipaddr ip wan; echo $ip").read()
ip2=str(ip).split("\n")[0]
return ip2
示例3: getLocalip
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def getLocalip(interface: str = "wlan0") -> str:
"""This function will return the Local IP Address of the interface"""
if "nux" in sys.platform:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
return socket.inet_ntoa(
fcntl.ioctl(
s.fileno(), 0x8915, struct.pack('256s',interface[:15])
)[20:24]
)
except IOError:
print("{}[!] Error, unable to detect local ip address.".format(Colors.FAIL))
print("[!] Check your connection to network {}".format(Colors.ENDC))
exit()
elif "darwin" in sys.platform:
return [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][0]
示例4: _resync
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def _resync(self):
"""
Check if the list of available nodes has changed. If any change is
detected, a new HashClient pointing to all currently available
nodes is returned, otherwise the current client is returned.
"""
# Collect the all Memcached pods' IP addresses
try:
_, _, ips = socket.gethostbyname_ex(self.host)
except socket.gaierror:
# The host could not be found. This mean that either the service is
# down or that no pods are running
ips = []
if set(ips) != set(self._ips):
# A different list of ips has been detected, so we generate
# a new client
self._ips = ips
if self._ips:
servers = [(ip, self.port) for ip in self._ips]
self._client = HashClient(servers, use_pooling=True)
else:
self._client = None
示例5: get_ips_addresses
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def get_ips_addresses(host):
"""
Get remote ip addresses
:param str host: target host
:return: list
"""
try:
_, _, ips_list = socket.gethostbyname_ex(host)
if not ips_list:
ips = ''
else:
ips = '['+', '.join(ips_list) +']'
except socket.gaierror:
ips = ''
return ips
示例6: kube_lookup_hostname
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def kube_lookup_hostname(self, ip, hostname, many=False):
ips = set()
ip = ip.split(':')[0]
if ip and ip != "":
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", ip):
ips.add(ip)
try:
(_, _, iplist) = socket.gethostbyname_ex(hostname)
ips |= set(iplist)
except socket.error as e:
pass
if many:
ips.add(hostname)
return sorted(list(ips))
else:
return sorted(list(ips))[0]
示例7: getQRImage
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def getQRImage():
path = os.path.join(os.getcwd(), "qrcode.jpg")
url = "https://login.weixin.qq.com/qrcode/" + uuid
r = s.get(url, stream=True)
# debugReq(r)
if r.status_code == 200:
with open(path, 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
import socket
ip = [l
for l in
([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]
if not ip.startswith("127.")][:1],
[[(sc.connect(('8.8.8.8', 80)), sc.getsockname()[0], sc.close())
for sc in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]])
if l][0][0]
print "[+] Please open http://" + ip + ":" + str(http_port) + "/qrcode.jpg or open " + path
time.sleep(1)
示例8: guess_ext_ip_from_local_info
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def guess_ext_ip_from_local_info(self):
try:
ip = get_my_wan_ip()
if DEBUG:
log('lm::guess_ext_ip_from_local_info: result of get_my_wan_ip()', ip)
if ip is None:
host = socket.gethostbyname_ex(socket.gethostname())
if DEBUG:
log('lm::guess_ext_ip_from_local_info: try to find ip from host: hostname', socket.gethostname(), 'result', host)
ipaddrlist = host[2]
for ip in ipaddrlist:
return ip
return '127.0.0.1'
return ip
except:
return '127.0.0.1'
示例9: should_be_discoverable_on_port
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def should_be_discoverable_on_port(context, host_port):
all_discovered = {}
for slave_ip in socket.gethostbyname_ex("mesosslave")[2]:
with mock.patch(
"paasta_tools.mesos_tools.socket.getfqdn",
return_value=slave_ip,
autospec=True,
):
discovered = marathon_tools.marathon_services_running_here()
all_discovered[slave_ip] = discovered
if discovered == [("bounce", "test1", host_port)]:
return
raise Exception(
"Did not find bounce.test1 in marathon_services_running_here for any of our slaves: %r",
all_discovered,
)
示例10: calculate_remote_masters
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def calculate_remote_masters(
cluster: str, system_paasta_config: SystemPaastaConfig
) -> Tuple[List[str], str]:
"""Given a cluster, do a DNS lookup of that cluster (which
happens to point, eventually, to the Mesos masters in that cluster).
Return IPs of those Mesos masters.
"""
cluster_fqdn = system_paasta_config.get_cluster_fqdn_format().format(
cluster=cluster
)
try:
_, _, ips = socket.gethostbyname_ex(cluster_fqdn)
output = None
except socket.gaierror as e:
output = f"ERROR while doing DNS lookup of {cluster_fqdn}:\n{e.strerror}\n "
ips = []
return (ips, output)
示例11: discover
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def discover(service_name, host = None, registrar = None, timeout = 2):
"""
discovers hosts running the given service
:param service_name: the service to look for
:param host: limit the discovery to the given host only (None means any host)
:param registrar: use this registry client to discover services. if None,
use the default UDPRegistryClient with the default settings.
:param timeout: the number of seconds to wait for a reply from the registry
if no hosts are found, raises DiscoveryError
:raises: ``DiscoveryError`` if no server is found
:returns: a list of (ip, port) pairs
"""
if registrar is None:
registrar = UDPRegistryClient(timeout = timeout)
addrs = registrar.discover(service_name)
if not addrs:
raise DiscoveryError("no servers exposing %r were found" % (service_name,))
if host:
ips = socket.gethostbyname_ex(host)[2]
addrs = [(h, p) for h, p in addrs if h in ips]
if not addrs:
raise DiscoveryError("no servers exposing %r were found on %r" % (service_name, host))
return addrs
示例12: audit
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def audit(arg):
domain = util.get_domain_root(arg)
tlds = util.list_from_file("database/sub_domain.txt")
unable_pro = "sbsbsbsbforw9scanunablepro"
hostnames = unable_pro + "." + domain
hostnames = hostnames.strip()
try:
l = socket.gethostbyname_ex(hostnames)
except socket.error:
l = 0
if l != 0:
security_info("域名存在泛解析 %s" % ("*." + domain), 'subdomain')
return
for pro in tlds:
hostnames = pro + "." + domain
hostnames = hostnames.strip()
try:
l = socket.gethostbyname_ex(hostnames)
security_info(str(l),'subdomain')
time.sleep(0.01)
except socket.error:
pass
示例13: override_system_resolver
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def override_system_resolver(resolver=None):
"""Override the system resolver routines in the socket module with
versions which use dnspython's resolver.
This can be useful in testing situations where you want to control
the resolution behavior of python code without having to change
the system's resolver settings (e.g. /etc/resolv.conf).
The resolver to use may be specified; if it's not, the default
resolver will be used.
@param resolver: the resolver to use
@type resolver: dns.resolver.Resolver object or None
"""
if resolver is None:
resolver = get_default_resolver()
global _resolver
_resolver = resolver
socket.getaddrinfo = _getaddrinfo
socket.getnameinfo = _getnameinfo
socket.getfqdn = _getfqdn
socket.gethostbyname = _gethostbyname
socket.gethostbyname_ex = _gethostbyname_ex
socket.gethostbyaddr = _gethostbyaddr
示例14: _publish_access
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
def _publish_access(self, *cmd, **kwargs):
check_exit_code = kwargs.get('check_exit_code', True)
outs = []
localserver_iplist = socket.gethostbyname_ex(socket.gethostname())[2]
for server in self.configuration.gpfs_nfs_server_list:
if server in localserver_iplist:
run_command = cmd
run_local = True
else:
sshlogin = self.configuration.gpfs_ssh_login
remote_login = sshlogin + '@' + server
run_command = ['ssh', remote_login] + list(cmd)
run_local = False
try:
out = utils.execute(*run_command,
run_as_root=run_local,
check_exit_code=check_exit_code)
except exception.ProcessExecutionError:
raise
outs.append(out)
return outs
示例15: get_names
# 需要导入模块: import socket [as 别名]
# 或者: from socket import gethostbyname_ex [as 别名]
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
# not entirely sure what the rules are here