當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。