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


Python ipaddr.IPv6Address方法代码示例

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


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

示例1: _get_ipv6_addr

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def _get_ipv6_addr(match):
    ipv6_main_part = match.group('ipv6_main_part')
    assert ipv6_main_part
    ipv6_suffix_in_ipv4_format = match.group('ipv6_suffix_in_ipv4_format')
    try:
        if ipv6_suffix_in_ipv4_format:
            assert ipv6_main_part.endswith(':')
            ipv6_suffix = _convert_ipv4_to_ipv6_suffix(ipv6_suffix_in_ipv4_format)
        else:
            assert ipv6_main_part == match.group('ipv6_addr')
            ipv6_suffix = ''
        ipv6_addr = ipaddr.IPv6Address(ipv6_main_part + ipv6_suffix).compressed
    except ipaddr.AddressValueError:
        ipv6_addr = match.group('ipv6_addr')
    assert is_pure_ascii(ipv6_addr)
    return ipv6_addr 
开发者ID:CERT-Polska,项目名称:n6,代码行数:18,代码来源:url_helpers.py

示例2: neighbor_solicitation_spoofing

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def neighbor_solicitation_spoofing(spoofed_source, target, myinterface, mac):
	solicited_node_multicast_address_prefix="ff02::1:ff"
	addr6 = ipaddr.IPv6Address(target)
	exploded=addr6.exploded
	length=len(exploded)
	suffix=exploded[(length-2):length]
	other=exploded[(length-4):(length-2)]
	the_other=exploded[(length-7):(length-5)]
	addresses={}
	#ns=ICMPv6ND_NS(tgt=target, R=0, S=0, O=1)/ICMPv6NDOptDstLLAddr(type=1,lladdr=mac)
	ns=scapy.layers.inet6.ICMPv6ND_NS(tgt=target)/scapy.layers.inet6.ICMPv6NDOptDstLLAddr(type=1,lladdr=mac)
	multi_address=solicited_node_multicast_address_prefix+the_other+":"+other+suffix
	packet=scapy.layers.inet6.IPv6(src=spoofed_source,dst=multi_address)/ns
	dest_multi_mac="33:33:ff:"+the_other+":"+other+":"+suffix
	ans,unan=scapy.sendrecv.srp(scapy.layers.l2.Ether(src=mac, dst=dest_multi_mac)/packet,iface=myinterface, timeout=2)
	for s,r in ans:
		try:
			addresses.update({r[IPv6].src:r[scapy.layers.l2.Ether].src})
		except:
			print "target",target, "was not found"
	return addresses 
开发者ID:aatlasis,项目名称:Chiron,代码行数:23,代码来源:attacks.py

示例3: FormatPackedIP

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def FormatPackedIP(packed_ip):
  """Formats packed binary data to a readable ip address.

  Args:
    packed_ip: The packed binary data to be converted.

  Returns:
    A readable ip address.

  Returns:
    bigquery_client.BigqueryInvalidQueryError: If the address is not valid.
  """
  packed_ip = ipaddr.Bytes(str(packed_ip))
  try:
    ip_address = ipaddr.IPv4Address(packed_ip)
    return str(ip_address)
  except ipaddr.AddressValueError as e:
    pass
  try:
    ip_address = ipaddr.IPv6Address(packed_ip)
    return str(ip_address)
  except ipaddr.AddressValueError as e:
    raise bigquery_client.BigqueryInvalidQueryError(e, None, None, None) 
开发者ID:google,项目名称:encrypted-bigquery-client,代码行数:25,代码来源:common_util.py

示例4: ParsePackedIP

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def ParsePackedIP(readable_ip):
  try:
    ip_address = ipaddr.IPv4Address(readable_ip)
    return str(ipaddr.v4_int_to_packed(int(ip_address)))
  except ValueError:
    pass
  try:
    ip_address = ipaddr.IPv6Address(readable_ip)
    return str(ipaddr.v6_int_to_packed(int(ip_address)))
  except ValueError:
    raise bigquery_client.BigqueryInvalidQueryError(
        'Invalid readable ip.', None, None, None)


# TODO(user): Implement all URL functions.
# Supported URL functions. 
开发者ID:google,项目名称:encrypted-bigquery-client,代码行数:18,代码来源:common_util.py

示例5: _convert_ipv4_to_ipv6_suffix

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def _convert_ipv4_to_ipv6_suffix(ipv6_suffix_in_ipv4_format):
    """
    >>> _convert_ipv4_to_ipv6_suffix('192.168.0.1')
    'c0a8:0001'
    """
    as_ipv4 = ipaddr.IPv4Address(ipv6_suffix_in_ipv4_format)
    as_int = int(as_ipv4)
    as_ipv6 = ipaddr.IPv6Address(as_int)
    ipv6_suffix = as_ipv6.exploded[-9:]
    assert _LAST_9_CHARS_OF_EXPLODED_IPV6_REGEX.search(ipv6_suffix)
    return ipv6_suffix 
开发者ID:CERT-Polska,项目名称:n6,代码行数:13,代码来源:url_helpers.py

示例6: _fix_value

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def _fix_value(self, value):
        value = super(IPv6Field, self)._fix_value(value)
        try:
            ipv6_obj = ipaddr.IPv6Address(value)
        except Exception:
            raise FieldValueError(public_message=(
                self.error_msg_template.format(ascii_str(value))))
        return ipv6_obj 
开发者ID:CERT-Polska,项目名称:n6,代码行数:10,代码来源:fields.py

示例7: ipv6Addr_to_bytes

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def ipv6Addr_to_bytes(addr):
    from ipaddr import IPv6Address
    if not ':' in addr:
        raise CLI_FormatExploreError()
    try:
        ip = IPv6Address(addr)
    except:
        raise UIn_BadIPv6Error()
    try:
        return [ord(b) for b in ip.packed]
    except:
        raise UIn_BadIPv6Error() 
开发者ID:nsg-ethz,项目名称:p4-utils,代码行数:14,代码来源:runtime_API.py

示例8: __init__

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def __init__(self, arg="::1/128", strict=False):

        # arg= _RGX_IPV6ADDR_NETMASK.sub(r'\1/\2', arg) # mangle IOS: 'addr mask'
        self.arg = arg
        self.dna = "IPv6Obj"

        try:
            mm = _RGX_IPV6ADDR.search(arg)
        except TypeError:
            if getattr(arg, "dna", "") == "IPv6Obj":
                ip_str = "{0}/{1}".format(str(arg.ip_object), arg.prefixlen)
                self.network_object = IPv6Network(ip_str, strict=False)
                self.ip_object = IPv6Address(str(arg.ip_object))
                return None
            elif isinstance(arg, IPv6Network):
                self.network_object = arg
                self.ip_object = IPv6Address(str(arg).split("/")[0])
                return None
            elif isinstance(arg, IPv6Address):
                self.network_object = IPv6Network(str(arg) + "/128")
                self.ip_object = IPv6Address(str(arg).split("/")[0])
                return None
            elif isinstance(arg, int):
                self.ip_object = IPv6Address(arg)
                self.network_object = IPv6Network(
                    str(self.ip_object) + "/128", strict=False
                )
                return None
            else:
                raise ValueError(
                    "IPv6Obj doesn't understand how to parse {0}".format(arg)
                )

        assert not (mm is None), "IPv6Obj couldn't parse {0}".format(arg)
        self.network_object = IPv6Network(arg, strict=strict)
        self.ip_object = IPv6Address(mm.group(1))

    # 'address_exclude', 'compare_networks', 'hostmask', 'ipv4_mapped', 'iter_subnets', 'iterhosts', 'masked', 'max_prefixlen', 'netmask', 'network', 'numhosts', 'overlaps', 'prefixlen', 'sixtofour', 'subnet', 'supernet', 'teredo', 'with_hostmask', 'with_netmask', 'with_prefixlen' 
开发者ID:mpenning,项目名称:ciscoconfparse,代码行数:40,代码来源:ccp_util.py

示例9: ip

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def ip(self):
        """Returns the address as an IPv6Address object."""
        return self.ip_object 
开发者ID:mpenning,项目名称:ciscoconfparse,代码行数:5,代码来源:ccp_util.py

示例10: netmask

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def netmask(self):
        """Returns the network mask as an IPv6Address object."""
        return self.network_object.netmask 
开发者ID:mpenning,项目名称:ciscoconfparse,代码行数:5,代码来源:ccp_util.py

示例11: hostmask

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def hostmask(self):
        """Returns the host mask as an IPv6Address object."""
        return self.network_object.hostmask 
开发者ID:mpenning,项目名称:ciscoconfparse,代码行数:5,代码来源:ccp_util.py

示例12: ipv6Addr_to_bytes

# 需要导入模块: import ipaddr [as 别名]
# 或者: from ipaddr import IPv6Address [as 别名]
def ipv6Addr_to_bytes(addr):
    try:
        ip = IPv6Address(addr)
    except AddressValueError:
        raise UserBadIPv6Error(addr)
    return ip.packed 
开发者ID:p4lang,项目名称:p4runtime-shell,代码行数:8,代码来源:bytes_utils.py


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