当前位置: 首页>>代码示例>>Python>>正文


Python socket.AI_CANONNAME属性代码示例

本文整理汇总了Python中socket.AI_CANONNAME属性的典型用法代码示例。如果您正苦于以下问题:Python socket.AI_CANONNAME属性的具体用法?Python socket.AI_CANONNAME怎么用?Python socket.AI_CANONNAME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在socket的用法示例。


在下文中一共展示了socket.AI_CANONNAME属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _gethostbyaddr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def _gethostbyaddr(ip):
    try:
        dns.ipv6.inet_aton(ip)
        sockaddr = (ip, 80, 0, 0)
        family = socket.AF_INET6
    except Exception:
        sockaddr = (ip, 80)
        family = socket.AF_INET
    (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD)
    aliases = []
    addresses = []
    tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP,
                          socket.AI_CANONNAME)
    canonical = tuples[0][3]
    for item in tuples:
        addresses.append(item[4][0])
    # XXX we just ignore aliases
    return (canonical, aliases, addresses) 
开发者ID:elgatito,项目名称:script.elementum.burst,代码行数:20,代码来源:resolver.py

示例2: validate_hostname

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def validate_hostname(hostname):
    """
    Validates using a FQDN rather than a short name as some
    APIs are very picky and SSL verification might fail.

    :param hostname: the hostname to validate
    :type hostname: str
    """
    try:
        if hostname == "localhost":
            #get real hostname
            hostname = socket.gethostname()
        if hostname.count('.') != 2:
            #get convert to FQDN if possible
            hostname = socket.getaddrinfo(
                socket.getfqdn(hostname), 0, 0, 0, 0,
                socket.AI_CANONNAME
            )[0][3]
    except socket.gaierror:
        raise InvalidHostnameFormatException(
            "Unable to find FQDN for host '{}'".format(hostname)
        )
    return hostname 
开发者ID:stdevel,项目名称:katprep,代码行数:25,代码来源:__init__.py

示例3: get_fqdn

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def get_fqdn():
    """
    Return the current fqdn of the machine, trying hard to return a meaningful
    name.

    In particular, it means working against a NetworkManager bug which seems to
    make C{getfqdn} return localhost6.localdomain6 for machine without a domain
    since Maverick.
    """
    fqdn = socket.getfqdn()
    if "localhost" in fqdn:
        # Try the heavy artillery
        fqdn = socket.getaddrinfo(socket.gethostname(), None, socket.AF_INET,
                                  socket.SOCK_DGRAM, socket.IPPROTO_IP,
                                  socket.AI_CANONNAME)[0][3]
        if "localhost" in fqdn:
            # Another fallback
            fqdn = socket.gethostname()
    return fqdn 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:21,代码来源:network.py

示例4: _gethostbyaddr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def _gethostbyaddr(ip):
    try:
        addr = dns.ipv6.inet_aton(ip)
        sockaddr = (ip, 80, 0, 0)
        family = socket.AF_INET6
    except:
        sockaddr = (ip, 80)
        family = socket.AF_INET
    (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD)
    aliases = []
    addresses = []
    tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP,
                          socket.AI_CANONNAME)
    canonical = tuples[0][3]
    for item in tuples:
        addresses.append(item[4][0])
    # XXX we just ignore aliases
    return (canonical, aliases, addresses) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:20,代码来源:resolver.py

示例5: _Dynamic_Resolve

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def _Dynamic_Resolve(self, request, response):
    addrs = {}
    for family, _, _, canonname, sa in socket.getaddrinfo(
        request.name(), 0, 0, socket.SOCK_STREAM, 0, socket.AI_CANONNAME):
      addrs.setdefault(self._AF_MAP.get(family), set()).add(
          _remote_socket_addr.inet_pton(self._TRANSLATED_AF_MAP[family], sa[0]))
      response.set_canonical_name(canonname)





      if canonname and canonname.lower() != request.name().lower():
        if not response.aliases_size():
          response.add_aliases(request.name())
    for af in request.address_families_list():
      for packed_addr in addrs.get(af, set()):
        response.add_packed_address(packed_addr) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:20,代码来源:_remote_socket_stub.py

示例6: _gethostbyaddr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def _gethostbyaddr(ip):
    try:
        thirdparty.dns.ipv6.inet_aton(ip)
        sockaddr = (ip, 80, 0, 0)
        family = socket.AF_INET6
    except:
        sockaddr = (ip, 80)
        family = socket.AF_INET
    (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD)
    aliases = []
    addresses = []
    tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP,
                          socket.AI_CANONNAME)
    canonical = tuples[0][3]
    for item in tuples:
        addresses.append(item[4][0])
    # XXX we just ignore aliases
    return (canonical, aliases, addresses) 
开发者ID:MrH0wl,项目名称:Cloudmare,代码行数:20,代码来源:resolver.py

示例7: hostname

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def hostname():
    """Hostname of the server."""
    treadmill_hostname = os.environ.get('TREADMILL_HOSTNAME')
    if treadmill_hostname:
        return treadmill_hostname.lower()

    host_name = socket.gethostname()
    port = 0
    family = 0
    socktype = 0
    proto = 0

    _family, _socktype, _proto, canonname, _sockaddr = socket.getaddrinfo(
        host_name,
        port,
        family,
        socktype,
        proto,
        socket.AI_CANONNAME)[0]

    return canonname.lower() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:23,代码来源:sysinfo.py

示例8: _gethostbyaddr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def _gethostbyaddr(ip):
    try:
        dns.ipv6.inet_aton(ip)
        sockaddr = (ip, 80, 0, 0)
        family = socket.AF_INET6
    except:
        sockaddr = (ip, 80)
        family = socket.AF_INET
    (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD)
    aliases = []
    addresses = []
    tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP,
                          socket.AI_CANONNAME)
    canonical = tuples[0][3]
    for item in tuples:
        addresses.append(item[4][0])
    # XXX we just ignore aliases
    return (canonical, aliases, addresses) 
开发者ID:entynetproject,项目名称:arissploit,代码行数:20,代码来源:resolver.py

示例9: _gethostbyname_ex

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def _gethostbyname_ex(name):
    aliases = []
    addresses = []
    tuples = _getaddrinfo(name, 0, socket.AF_INET, socket.SOCK_STREAM,
                          socket.SOL_TCP, socket.AI_CANONNAME)
    canonical = tuples[0][3]
    for item in tuples:
        addresses.append(item[4][0])
    # XXX we just ignore aliases
    return (canonical, aliases, addresses) 
开发者ID:elgatito,项目名称:script.elementum.burst,代码行数:12,代码来源:resolver.py

示例10: _gethostbyname_ex

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def _gethostbyname_ex(name):
    aliases = []
    addresses = []
    tuples = _getaddrinfo(name, 0, socket.AF_INET, socket.SOCK_STREAM,
                         socket.SOL_TCP, socket.AI_CANONNAME)
    canonical = tuples[0][3]
    for item in tuples:
        addresses.append(item[4][0])
    # XXX we just ignore aliases
    return (canonical, aliases, addresses) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:12,代码来源:resolver.py

示例11: get_ip_mac_fqdn

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def get_ip_mac_fqdn():

    interfaces = get_interface_list()

    primary_interface = sorted(interfaces, key=lambda k: k['ifaceName'])[0]
    ip_address = primary_interface['ipaddress']
    fqdn = socket.getaddrinfo(socket.gethostname(), 0, 0, 0, 0, socket.AI_CANONNAME)[0][3]
    mac_address = primary_interface['macaddress']
    return ip_address, mac_address, fqdn 
开发者ID:vulnersCom,项目名称:vulners-agent,代码行数:11,代码来源:osdetect.py

示例12: __str__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_CANONNAME [as 别名]
def __str__(self):
        if self.fqdn is None:
            #
            # If the SSH config contains AddressFamily, use that when
            # determining  the local host's FQDN. Using socket.getfqdn() from
            # the standard library is the most general solution, but can
            # result in noticeable delays on some platforms when IPv6 is
            # misconfigured or not available, as it calls getaddrinfo with no
            # address family specified, so both IPv4 and IPv6 are checked.
            #

            # Handle specific option
            fqdn = None
            address_family = self.config.get('addressfamily', 'any').lower()
            if address_family != 'any':
                try:
                    family = socket.AF_INET if address_family == 'inet' \
                        else socket.AF_INET6
                    results = socket.getaddrinfo(
                        self.host,
                        None,
                        family,
                        socket.SOCK_DGRAM,
                        socket.IPPROTO_IP,
                        socket.AI_CANONNAME
                    )
                    for res in results:
                        af, socktype, proto, canonname, sa = res
                        if canonname and '.' in canonname:
                            fqdn = canonname
                            break
                # giaerror -> socket.getaddrinfo() can't resolve self.host
                # (which is from socket.gethostname()). Fall back to the
                # getfqdn() call below.
                except socket.gaierror:
                    pass
            # Handle 'any' / unspecified
            if fqdn is None:
                fqdn = socket.getfqdn()
            # Cache
            self.fqdn = fqdn
        return self.fqdn 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:44,代码来源:config.py


注:本文中的socket.AI_CANONNAME属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。