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