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


Python netifaces.AF_INET6属性代码示例

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


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

示例1: video_invite

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def video_invite():
    global IsOpen, Version, AudioOpen
    if Version == 4:
        host_name = socket.gethostbyname(socket.getfqdn(socket.gethostname()))
    else:
        host_name = [i['addr'] for i in ifaddresses(interfaces()[-2]).setdefault(AF_INET6, [{'addr': 'No IP addr'}])][
            -1]

    invite = 'INVITE' + host_name + ':;' + user + ':;' + chat
    s.send(invite.encode())
    if not IsOpen:
        vserver = vachat.Video_Server(10087, Version)
        if AudioOpen:
            aserver = vachat.Audio_Server(10088, Version)
            aserver.start()
        vserver.start()
        IsOpen = True 
开发者ID:11ze,项目名称:The-chat-room,代码行数:19,代码来源:client-test2.py

示例2: get_interfaces

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def get_interfaces():

    interfaces = netifaces.interfaces()
    interfaces.remove('lo')

    out_interfaces = dict()

    for interface in interfaces:
        addrs = netifaces.ifaddresses(interface)
        out_addrs = dict()
        if netifaces.AF_INET in addrs.keys():
            out_addrs["ipv4"] = addrs[netifaces.AF_INET]
        if netifaces.AF_INET6 in addrs.keys():
            out_addrs["ipv6"] = addrs[netifaces.AF_INET6]
        out_interfaces[interface] = out_addrs

    return out_interfaces 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:19,代码来源:topology.py

示例3: _get_addresses_from_ifaddresses

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def _get_addresses_from_ifaddresses(self, ifaddresses):
        """Get addresses of a given interface

        :param ifaddresses: raw addresses of interface (from netifaces)
        :return: list of addresses
        """
        addresses = []
        for family in ifaddresses:
            if family != netifaces.AF_LINK:  # no hwaddr
                for addr in ifaddresses[family]:
                    a = addr["addr"]
                    if family == netifaces.AF_INET6:
                        a = self._remove_ipv6_special_stuff(a)
                    addresses.append(
                        Address(address=a, family=family))

        return addresses 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:19,代码来源:GEventNetworkManager.py

示例4: canonicalize

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def canonicalize(self, ip_str):
        """
        Parse an IP string for listen to IPAddress content.
        """
        try:
            if ':' in ip_str:
                self.version = 'ipv6'
                if '%' in ip_str:
                    ip_str, scope = ip_str.split('%')
                    self.scope = int(scope)
                self.packed_addr = socket.inet_pton(socket.AF_INET6, ip_str)
                self.addr = socket.inet_ntop(socket.AF_INET6, self.packed_addr)
            else:
                self.version = 'ipv4'
                self.packed_addr = socket.inet_pton(socket.AF_INET, ip_str)
                self.addr = socket.inet_ntop(socket.AF_INET, self.packed_addr)
        except socket.error as detail:
            if 'illegal IP address' in str(detail):
                self.addr = ip_str
                self.version = 'hostname' 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:22,代码来源:utils_net.py

示例5: get_all_ips

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def get_all_ips():
    """
    Find all IPs for this machine.

    :return: ``set`` of IP addresses (``IPAddress``).
    """
    ips = set()
    interfaces = netifaces.interfaces()
    for interface in interfaces:
        addresses = netifaces.ifaddresses(interface)
        for address_family in (netifaces.AF_INET, netifaces.AF_INET6):
            family_addresses = addresses.get(address_family)
            if not family_addresses:
                continue
            for address in family_addresses:
                ips.add(ipaddress_from_string(address['addr']))
    return ips 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:19,代码来源:_net.py

示例6: get_ip_for_interface

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def get_ip_for_interface(interface_name, ipv6=False):
        """
        Get the ip address in IPv4 or IPv6 for a specific network interface

        :param str interace_name: declares the network interface name for which the ip should be accessed
        :param bool ipv6: Boolean indicating if the ipv6 address should be rertrieved
        :return: (str ipaddress, byte ipaddress_bytes) returns a tuple with the ip address as a string and in bytes
        """
        addresses = netifaces.ifaddresses(interface_name)

        if netifaces.AF_INET6 in addresses and ipv6:
            # Use the normal ipv6 address
            addr = addresses[netifaces.AF_INET6][0]['addr'].split('%')[0]
            bytes_addr = ipaddress.IPv6Address(addr).packed
        elif netifaces.AF_INET in addresses and not ipv6:
            addr = addresses[netifaces.AF_INET][0]['addr']
            bytes_addr = socket.inet_aton(addr)
        else:
            addr = None
            bytes_addr = None

        return addr, bytes_addr 
开发者ID:hexway,项目名称:apple_bleee,代码行数:24,代码来源:util.py

示例7: __init__

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def __init__(self,
                 data   # Data suitable for this class
                 ):

        valid, message = data_is_valid(data)
        if not valid:
            raise ValueError("Invalid data: %s" % message)

        self.cidrs = []
        for iface in netifaces.interfaces():
            ifaddrs = netifaces.ifaddresses(iface)
            if netifaces.AF_INET in ifaddrs:
                for ifaddr in ifaddrs[netifaces.AF_INET]:
                    if 'addr' in ifaddr:
                        self.cidrs.append(ipaddress.ip_network(unicode(ifaddr['addr'])))
            if netifaces.AF_INET6 in ifaddrs:
                for ifaddr in ifaddrs[netifaces.AF_INET6]:
                    if 'addr' in ifaddr:
                        #add v6 but remove stuff like %eth0 that gets thrown on end of some addrs
                        self.cidrs.append(ipaddress.ip_network(unicode(ifaddr['addr'].split('%')[0]))) 
开发者ID:perfsonar,项目名称:pscheduler,代码行数:22,代码来源:localif.py

示例8: get_interface_ipv6_gateway

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def get_interface_ipv6_gateway(self,
                                   interface_name: str = 'eth0',
                                   exit_on_failure: bool = True,
                                   exit_code: int = 24,
                                   quiet: bool = False) -> Union[None, str]:
        """
        Get IPv6 gateway address on network interface
        :param interface_name: Network interface name (default: 'eth0')
        :param exit_on_failure: Exit in case of error (default: False)
        :param exit_code: Set exit code integer (default: 24)
        :param quiet: Quiet mode, if True no console output (default: False)
        :return: IPv6 address string (example: 'fd00::1') or None in case of error
        """
        if interface_name in self._network_interfaces_settings.keys():
            if self._network_interfaces_settings[interface_name]['ipv6-gateway'] is not None:
                return self._network_interfaces_settings[interface_name]['ipv6-gateway']

        return self.get_interface_gateway(interface_name=interface_name,
                                          network_type=AF_INET6,
                                          exit_on_failure=exit_on_failure,
                                          exit_code=exit_code,
                                          quiet=quiet) 
开发者ID:raw-packet,项目名称:raw-packet,代码行数:24,代码来源:base.py

示例9: ipv6_address_validation

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def ipv6_address_validation(self,
                                ipv6_address: str = 'fd00::1',
                                exit_on_failure: bool = False,
                                exit_code: int = 28,
                                quiet: bool = True) -> bool:
        """
        Validate IPv6 address string
        :param ipv6_address: IPv6 address string (example: 'fd00::1')
        :param exit_on_failure: Exit in case of error (default: False)
        :param exit_code: Set exit code integer (default: 28)
        :param quiet: Quiet mode, if True no console output (default: False)
        :return: True if a valid IPv6 address or False if not
        """
        try:
            sock.inet_pton(sock.AF_INET6, ipv6_address)
            return True
        except sock.error:
            if not quiet:
                self.print_error('Failed to validate IPv6 address: ', str(ipv6_address))
            if exit_on_failure:
                exit(exit_code)
            return False 
开发者ID:raw-packet,项目名称:raw-packet,代码行数:24,代码来源:base.py

示例10: active

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def active(self):
        if not self.enabled():
            return False
        iface = self.interface()
        if not iface:
            return False

        store = _MacOSNetworkHelper.create_dynamic_store()
        # TODO: This doesn't actually report active correctly
        plist = SCDynamicStoreCopyValue(store, "State:/Network/Interface/{}/Link".format(iface))
        if not plist or 'Active' not in plist:
            L.warning("Can't get link state for {}. Got {}".format(self, plist))
            return False

        if not plist['Active']:
            return False

        ifaces = netifaces.ifaddresses(iface)
        return netifaces.AF_INET in ifaces or netifaces.AF_INET6 in ifaces 
开发者ID:expressvpn,项目名称:expressvpn_leak_testing,代码行数:21,代码来源:locations_and_services.py

示例11: run

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def run(self):
        """
        Gather information about network interfaces and write it to the
        sysinfo output.

        @return: A succeeded C{Deferred}.
        """
        device_info = self._get_device_info()
        for info in sorted(device_info, key=itemgetter('interface')):
            interface = info["interface"]
            ipv4_addresses = info["ip_addresses"].get(AF_INET, [])
            ipv6_addresses = info["ip_addresses"].get(AF_INET6, [])
            for addr in ipv4_addresses:
                self._sysinfo.add_header(
                    "IPv4 address for %s" % interface, addr['addr'])
            for addr in ipv6_addresses:
                self._sysinfo.add_header(
                    "IPv6 address for %s" % interface, addr['addr'])

        return succeed(None) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:22,代码来源:network.py

示例12: get_ip_addresses

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def get_ip_addresses(ifaddresses):
    """Return all IP addresses of an interfaces.

    Returns the same structure as L{ifaddresses}, but filtered to keep
    IP addresses only.

    @param ifaddresses: a dict as returned by L{netifaces.ifaddresses} or
        the address data in L{get_active_interfaces}'s output.
    """
    results = {}
    if netifaces.AF_INET in ifaddresses:
        results[netifaces.AF_INET] = ifaddresses[netifaces.AF_INET]
    if netifaces.AF_INET6 in ifaddresses:
        # Ignore link-local IPv6 addresses (fe80::/10).
        global_addrs = [addr for addr in ifaddresses[netifaces.AF_INET6]
                        if not addr['addr'].startswith('fe80:')]
        if global_addrs:
            results[netifaces.AF_INET6] = global_addrs

    return results 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:22,代码来源:network.py

示例13: _ip_addresses

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def _ip_addresses():
    ip_list = set()
    for iface in netifaces.interfaces():
        if netifaces.AF_INET in netifaces.ifaddresses(iface):
            for link in netifaces.ifaddresses(iface)[netifaces.AF_INET]:
                ip_list.add(link['addr'])
        if netifaces.AF_INET6 in netifaces.ifaddresses(iface):
            for link in netifaces.ifaddresses(iface)[netifaces.AF_INET6]:
                if '%' in link['addr']:
                    continue
                ip_list.add(link['addr'])

    ip_list.discard('::1')
    ip_list.discard('127.0.0.1')

    return list(ip_list) 
开发者ID:SUSE,项目名称:DeepSea,代码行数:18,代码来源:iscsi.py

示例14: _get_local_ips

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def _get_local_ips():
    ifaces = netifaces.interfaces()
    ret = []
    for iface in ifaces:
        if iface == "lo":
            continue
        addrs = netifaces.ifaddresses(iface)
        ret.append(
            {
                iface: {
                    "ipv4": addrs.get(netifaces.AF_INET),
                    "ipv6": addrs.get(netifaces.AF_INET6),
                },
            }
        )
    return ret 
开发者ID:cloudbase,项目名称:coriolis,代码行数:18,代码来源:utils.py

示例15: best_remote_address

# 需要导入模块: import netifaces [as 别名]
# 或者: from netifaces import AF_INET6 [as 别名]
def best_remote_address():
    """
    Returns the "best" non-localback IP address for the local host, if
    possible.  The "best" IP address is that bound to either the default
    gateway interface, if any, else the arbitrary first interface found.

    IPv4 is preferred, but IPv6 will be used if no IPv4 interfaces/addresses
    are available.
    """
    default_gateway   = net.gateways().get("default", {})
    default_interface = default_gateway.get(net.AF_INET,  (None, None))[1] \
                     or default_gateway.get(net.AF_INET6, (None, None))[1] \
                     or net.interfaces()[0]

    interface_addresses = net.ifaddresses(default_interface).get(net.AF_INET)  \
                       or net.ifaddresses(default_interface).get(net.AF_INET6) \
                       or []

    addresses = [
        address["addr"]
            for address in interface_addresses
             if address.get("addr")
    ]

    return addresses[0] if addresses else None 
开发者ID:nextstrain,项目名称:cli,代码行数:27,代码来源:view.py


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