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


Python ipaddress.IPv6Network方法代码示例

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


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

示例1: insert_network

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def insert_network(self, prefix, data_offset, strict = True):
        self.entries_count += 1
        ipnet = ipaddress.ip_network(prefix, strict=False)

        if ipnet.version == 6 and self.ip_version != 6:
            raise Exception('Encoder: insert_network: cannot add IPv6 address in IPv4 table')

        if ipnet.version == 4 and self.ip_version == 6:
            base4in6 = ipaddress.IPv6Address(u'::ffff:0:0')
            v4in6addr = ipaddress.IPv6Address(int(ipnet.network_address)+int(base4in6))

            # Maxmind DBs skips the first 96 bits (do not include the 0xffff)
            if self.compat:
                v4in6addr = ipaddress.IPv6Address(int(ipnet.network_address))

            v4in6addr_plen = ipnet.prefixlen + 96
            ipnet = ipaddress.IPv6Network(u'{}/{}'.format(str(v4in6addr), v4in6addr_plen), strict=False)

        #print(ipnet)
        self.add_to_trie(ipnet, data_offset, strict=strict) 
开发者ID:cloudflare,项目名称:py-mmdb-encoder,代码行数:22,代码来源:__init__.py

示例2: prehandle_roa

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def prehandle_roa(asn_table: dict, args):
    roa = route_to_roa(asn_table)
    max_prefixlen = IPv4Network(0).max_prefixlen
    roa4 = filter(lambda item: isinstance(item["prefix"], IPv4Network), roa)
    roa6 = filter(lambda item: isinstance(item["prefix"], IPv6Network), roa)
    if args.ipv4:
        roa6 = []
    elif args.ipv6:
        roa4 = []
    roa4 = [
        r
        for r in roa4
        if r["prefix"].prefixlen <= args.max or r["prefix"].prefixlen == max_prefixlen
    ]
    roa6 = [r for r in roa6 if r["prefix"].prefixlen <= args.max6]
    for r in roa4:
        r["maxLength"] = args.max
        if r["prefix"].prefixlen == max_prefixlen:
            r["maxLength"] = max_prefixlen
    for r in roa6:
        r["maxLength"] = args.max6
    for r in (*roa4, *roa6):
        r["prefix"] = r["prefix"].with_prefixlen
    return roa4, roa6 
开发者ID:NeoCloud,项目名称:NeoNetwork,代码行数:26,代码来源:roa.py

示例3: __init__

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def __init__(self, value):
        if not isinstance(
            value,
            (
                ipaddress.IPv4Address,
                ipaddress.IPv6Address,
                ipaddress.IPv4Network,
                ipaddress.IPv6Network
            )
        ):
            raise TypeError(
                "value must be an instance of ipaddress.IPv4Address, "
                "ipaddress.IPv6Address, ipaddress.IPv4Network, or "
                "ipaddress.IPv6Network"
            )

        self._value = value 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:19,代码来源:general_name.py

示例4: testGetSubnets3

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def testGetSubnets3(self):
        subnets = [str(x) for x in self.ipv4_network.subnets(8)]
        self.assertEqual(subnets[:3],
            ['1.2.3.0/32', '1.2.3.1/32', '1.2.3.2/32'])
        self.assertEqual(subnets[-3:],
            ['1.2.3.253/32', '1.2.3.254/32', '1.2.3.255/32'])
        self.assertEqual(len(subnets), 256)

        ipv6_network = ipaddress.IPv6Network('2001:658:22a:cafe::/120')
        subnets = [str(x) for x in ipv6_network.subnets(8)]
        self.assertEqual(subnets[:3],
            ['2001:658:22a:cafe::/128',
             '2001:658:22a:cafe::1/128',
             '2001:658:22a:cafe::2/128'])
        self.assertEqual(subnets[-3:],
            ['2001:658:22a:cafe::fd/128',
             '2001:658:22a:cafe::fe/128',
             '2001:658:22a:cafe::ff/128'])
        self.assertEqual(len(subnets), 256) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:21,代码来源:test_ipaddress.py

示例5: _str_conf

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def _str_conf(self, conf_v):
        if isinstance(conf_v, (bool, str, int)):
            return conf_v
        if isinstance(conf_v, (
                ipaddress.IPv4Address, ipaddress.IPv4Interface, ipaddress.IPv4Network,
                ipaddress.IPv6Address, ipaddress.IPv6Interface, ipaddress.IPv6Network)):
            return str(conf_v)
        if isinstance(conf_v, (dict, OrderedDict)):
            return {str(i): self._str_conf(j) for i, j in conf_v.items() if j is not None}
        if isinstance(conf_v, (list, tuple, frozenset)):
            return tuple([self._str_conf(i) for i in conf_v if i is not None])
        if isinstance(conf_v, Conf):
            for i in ('name', '_id'):
                if hasattr(conf_v, i):
                    return getattr(conf_v, i)
        return None 
开发者ID:faucetsdn,项目名称:faucet,代码行数:18,代码来源:conf.py

示例6: __init__

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def __init__(self,
                 interface="deckard",
                 ip4_range=IPv4Network('127.127.0.0/16'),
                 ip6_range=IPv6Network('fd00:dec::/32')):
        self.ip4_internal_range = ip4_range
        self.ip6_internal_range = ip6_range
        self.ip4_iterator = (host for host in ip4_range)
        self.ip6_iterator = (host for host in ip6_range)
        self.added_addresses = set()
        self.interface = interface

        self._ip = IPRoute()
        try:
            self._dev = self._setup_interface()
        except NetlinkError:
            raise RuntimeError(f"Couldn't set interface `{self.interface}` up.") 
开发者ID:CZ-NIC,项目名称:deckard,代码行数:18,代码来源:networking.py

示例7: generate_pubkey_ipv6

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def generate_pubkey_ipv6(network: Config.NetworkType, node: Config.NodeType) -> Optional[str]:
    if 'AddressPoolIPv6' not in network:
        return None
    address_pool = ipaddress.IPv6Network(network['AddressPoolIPv6'], strict=False)

    if 'PrivateKey' not in node:
        return None
    secret_base64: str = node['PrivateKey']
    secret: bytes = binascii.a2b_base64(secret_base64)
    if len(secret) != 32:
        return None

    host = ipaddress.IPv6Address(pubkey(secret)[-16:])
    ipv6 = ipaddress.IPv6Address(int(address_pool.network_address) | (int(host) & int(address_pool.hostmask)))

    return ipv6.compressed + '/' + str(address_pool.prefixlen) 
开发者ID:m13253,项目名称:VxWireguard-Generator,代码行数:18,代码来源:common.py

示例8: supernet

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def supernet(self, prefixlen_diff=1):
    """Override ipaddress.IPv6Network supernet so we can maintain comments.

    See ipaddress.IPv6Network.Supernet for complete documentation.
    Args:
      prefixlen_diff: Prefix length difference.

    Returns:
      An IPv4 object

    Raises:
      PrefixlenDiffInvalidError: Raised when prefixlen - prefixlen_diff results
        in a negative number.
    """
    if self.prefixlen == 0:
      return self
    if self.prefixlen - prefixlen_diff < 0:
      raise PrefixlenDiffInvalidError(
          'current prefixlen is %d, cannot have a prefixlen_diff of %d' % (
              self.prefixlen, prefixlen_diff))
    ret_addr = IPv6(ipaddress.IPv6Network.supernet(self, prefixlen_diff),
                    comment=self.text, token=self.token)
    return ret_addr

  # Backwards compatibility name from v1. 
开发者ID:google,项目名称:capirca,代码行数:27,代码来源:nacaddr.py

示例9: make_ipv6_prefix

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def make_ipv6_prefix(prefix_str):
    ipv6_network = ipaddress.IPv6Network(prefix_str)
    address = ipv6_network.network_address.packed
    prefixlen = ipv6_network.prefixlen
    ipv6_prefix = common.ttypes.IPv6PrefixType(address, prefixlen)
    prefix = common.ttypes.IPPrefixType(ipv6prefix=ipv6_prefix)
    return prefix 
开发者ID:brunorijsman,项目名称:rift-python,代码行数:9,代码来源:packet_common.py

示例10: ipv6_prefix_str

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def ipv6_prefix_str(ipv6_prefix):
    address = ipv6_prefix.address.rjust(16, b"\x00")
    length = ipv6_prefix.prefixlen
    return str(ipaddress.IPv6Network((address, length))) 
开发者ID:brunorijsman,项目名称:rift-python,代码行数:6,代码来源:packet_common.py

示例11: finalize_args_and_env

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def finalize_args_and_env(args, env):
    global providers

    # use the tunnel device as the VPN name if unspecified
    if args.name is None:
        args.name = env.tundev

    # autodetect parent or grandparent process (skipping intermediary shell)
    if args.ppid is None:
        args.ppid = providers.process.ppid_of(None)
        exe = providers.process.pid2exe(args.ppid)
        if exe and os.path.basename(exe) in ('dash','bash','sh','tcsh','csh','ksh','zsh'):
            args.ppid = providers.process.ppid_of(args.ppid)

    # use the list from the env if --domain wasn't specified, but start with an
    # empty list if it was specified; hence can't use 'default' here:
    if args.domain is None:
        args.domain = env.domain

    args.subnets = []
    args.exc_subnets = []
    args.hosts = []
    args.aliases = {}
    for x in args.routes:
        if isinstance(x, (IPv4Network, IPv6Network)):
            args.subnets.append(x)
        elif isinstance(x, str):
            args.hosts.append(x)
        else:
            hosts, ip = x
            args.aliases.setdefault(ip, []).extend(hosts)
    if args.route_internal:
        if env.network: args.subnets.append(env.network)
        if env.network6: args.subnets.append(env.network6)
    if args.route_splits:
        args.subnets.extend(env.splitinc)
        args.exc_subnets.extend(env.splitexc) 
开发者ID:dlenski,项目名称:vpn-slice,代码行数:39,代码来源:__main__.py

示例12: _check_if_private

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def _check_if_private(address: str, address_type: str) -> bool:
        if address_type == "ipv6":
            ip_list = [str(ip) for ip in IPv6Network(address)]
        else:
            ip_list = [str(ip) for ip in IPv4Network(address)]

        if ip_address(ip_list[0]).is_private and ip_address(ip_list[-1]).is_private:
            return True
        return False 
开发者ID:rapid7,项目名称:insightconnect-plugins,代码行数:11,代码来源:action.py

示例13: register_ipaddress

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def register_ipaddress(conn_or_curs=None):
    """
    Register conversion support between `ipaddress` objects and `network types`__.

    :param conn_or_curs: the scope where to register the type casters.
        If `!None` register them globally.

    After the function is called, PostgreSQL :sql:`inet` values will be
    converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface`
    objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or
    `~ipaddress.IPv6Network`.

    .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html
    """
    global ipaddress
    import ipaddress

    global _casters
    if _casters is None:
        _casters = _make_casters()

    for c in _casters:
        register_type(c, conn_or_curs)

    for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface,
              ipaddress.IPv4Network, ipaddress.IPv6Network]:
        register_adapter(t, adapt_ipaddress) 
开发者ID:tryolabs,项目名称:aws-workshop,代码行数:29,代码来源:_ipaddress.py

示例14: _validate_ip_name

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [as 别名]
def _validate_ip_name(self, tree):
        if any(isinstance(name, IPAddress) and not isinstance(
            name.value, (ipaddress.IPv4Network, ipaddress.IPv6Network)
        ) for name in tree):
            raise TypeError(
                "IPAddress name constraints must be an IPv4Network or"
                " IPv6Network object"
            ) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:10,代码来源:extensions.py

示例15: __init__

# 需要导入模块: import ipaddress [as 别名]
# 或者: from ipaddress import IPv6Network [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)

            pairs = []

            for ifaddr in ifaddrs[netifaces.AF_INET] \
                if netifaces.AF_INET in ifaddrs else []:
                self.cidrs.append(ipaddress.IPv4Network(
                    unicode("%s/%s" % (ifaddr["addr"], ifaddr["netmask"])),
                    strict=False  # Don't complain about host bits being set.
                ))

            for ifaddr in ifaddrs[netifaces.AF_INET6] \
                if netifaces.AF_INET6 in ifaddrs else []:
                self.cidrs.append(ipaddress.IPv6Network(
                    unicode("%s/%s" % (
                        ifaddr["addr"].split("%")[0],
                        ipv6_netmask_size(ifaddr["netmask"]))),
                    strict=False  # Don't complain about host bits being set.
                )) 
开发者ID:perfsonar,项目名称:pscheduler,代码行数:33,代码来源:localsubnet.py


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