ipv6_is_match()ipv6_is_match()

匹配两个 IPv6 或 IPv4 网络地址字符串。Matches two IPv6 or IPv4 network address strings. 分析并比较两个 IPv6/IPv4 字符串,同时考虑根据参数前缀和可选的 PrefixMask 参数计算出的组合 IP 前缀掩码。The two IPv6/IPv4 strings are parsed and compared while accounting for the combined IP-prefix mask calculated from argument prefixes, and the optional PrefixMask argument.

ipv6_is_match('::ffff:7f00:1', '127.0.0.1') == true
ipv6_is_match('fe80::85d:e82c:9446:7994', 'fe80::85d:e82c:9446:7995') == false
ipv6_is_match('192.168.1.1/24', '192.168.1.255/24') == true
ipv6_is_match('fe80::85d:e82c:9446:7994/127', 'fe80::85d:e82c:9446:7995/127') == true
ipv6_is_match('fe80::85d:e82c:9446:7994', 'fe80::85d:e82c:9446:7995', 127) == true

备注

此函数可以接受并比较表示 IPv6 和 IPv4 网络地址的参数。The function can accept and compare arguments representing both IPv6 and IPv4 network addresses. 如果调用方知道参数采用 IPv4 格式,请使用 ipv4_is_match() 函数。If the caller knows that arguments are in IPv4 format, use the ipv4_is_match() function. 此函数将产生更好的运行时性能。This function will result in better runtime performance.

语法Syntax

ipv6_is_match(Expr1, Expr2[ ,PrefixMask])ipv6_is_match(Expr1, Expr2[ ,PrefixMask])

参数Arguments

  • Expr1、Expr2:表示 IPv6 或 IPv4 地址的字符串表达式。Expr1, Expr2: A string expression representing an IPv6 or IPv4 address. 可以使用 IP 前缀表示法对 IPv6 和 IPv4 字符串进行掩码操作。IPv6 and IPv4 strings can be masked using IP-prefix notation.
  • PrefixMask:从 0 到 128 的整数,表示所考虑的最有效位的数目。PrefixMask: An integer from 0 to 128 representing the number of most-significant bits that are taken into account.

IP 前缀表示法IP-prefix notation

IP 地址可以通过斜杠 (/) 字符使用 IP-prefix notation 进行定义。IP addresses can be defined with IP-prefix notation using a slash (/) character. 斜杠 (/) 左边的 IP 地址是基本 IP 地址。The IP address to the LEFT of the slash (/) is the base IP address. 斜杠 (/) 右边的数字(1 到 127)是网络掩码中连续位的数目。The number (1 to 127) to the RIGHT of the slash (/) is the number of contiguous 1 bit in the netmask.

示例:fe80::85d:e82c:9446:7994/120 将有一个包含 120 个连续位的关联网络/子网掩码。For example, fe80::85d:e82c:9446:7994/120 will have an associated net/subnetmask containing 120 contiguous bits.

返回Returns

  • true:如果第一个 IPv6/IPv4 字符串参数的长表示形式等于第二个 IPv6/IPv4 字符串参数。true: If the long representation of the first IPv6/IPv4 string argument is equal to the second IPv6/IPv4 string argument.
  • false:其他情况。false: Otherwise.
  • null:如果两个 IPv6/IPv4 字符串之一转换不成功。null: If conversion for one of the two IPv6/IPv4 strings wasn't successful.

示例Examples

IPv6/IPv4 比较相等的情况 - IPv6/IPv4 字符串中指定的 IP 前缀表示法IPv6/IPv4 comparison equality case - IP-prefix notation specified inside the IPv6/IPv4 strings

datatable(ip1_string:string, ip2_string:string)
[
 // IPv4 are compared as IPv6 addresses
 '192.168.1.1',    '192.168.1.1',       // Equal IPs
 '192.168.1.1/24', '192.168.1.255',     // 24 bit IP4-prefix is used for comparison
 '192.168.1.1',    '192.168.1.255/24',  // 24 bit IP4-prefix is used for comparison
 '192.168.1.1/30', '192.168.1.255/24',  // 24 bit IP4-prefix is used for comparison
  // IPv6 cases
 'fe80::85d:e82c:9446:7994', 'fe80::85d:e82c:9446:7994',         // Equal IPs
 'fe80::85d:e82c:9446:7994/120', 'fe80::85d:e82c:9446:7998',     // 120 bit IP6-prefix is used for comparison
 'fe80::85d:e82c:9446:7994', 'fe80::85d:e82c:9446:7998/120',     // 120 bit IP6-prefix is used for comparison
 'fe80::85d:e82c:9446:7994/120', 'fe80::85d:e82c:9446:7998/120', // 120 bit IP6-prefix is used for comparison
 // Mixed case of IPv4 and IPv6
 '192.168.1.1',      '::ffff:c0a8:0101', // Equal IPs
 '192.168.1.1/24',   '::ffff:c0a8:01ff', // 24 bit IP-prefix is used for comparison
 '::ffff:c0a8:0101', '192.168.1.255/24', // 24 bit IP-prefix is used for comparison
 '::192.168.1.1/30', '192.168.1.255/24', // 24 bit IP-prefix is used for comparison
]
| extend result = ipv6_is_match(ip1_string, ip2_string)
ip1_stringip1_string ip2_stringip2_string resultresult
192.168.1.1192.168.1.1 192.168.1.1192.168.1.1 11
192.168.1.1/24192.168.1.1/24 192.168.1.255192.168.1.255 11
192.168.1.1192.168.1.1 192.168.1.255/24192.168.1.255/24 11
192.168.1.1/30192.168.1.1/30 192.168.1.255/24192.168.1.255/24 11
fe80::85d:e82c:9446:7994fe80::85d:e82c:9446:7994 fe80::85d:e82c:9446:7994fe80::85d:e82c:9446:7994 11
fe80::85d:e82c:9446:7994/120fe80::85d:e82c:9446:7994/120 fe80::85d:e82c:9446:7998fe80::85d:e82c:9446:7998 11
fe80::85d:e82c:9446:7994fe80::85d:e82c:9446:7994 fe80::85d:e82c:9446:7998/120fe80::85d:e82c:9446:7998/120 11
fe80::85d:e82c:9446:7994/120fe80::85d:e82c:9446:7994/120 fe80::85d:e82c:9446:7998/120fe80::85d:e82c:9446:7998/120 11
192.168.1.1192.168.1.1 ::ffff:c0a8:0101::ffff:c0a8:0101 11
192.168.1.1/24192.168.1.1/24 ::ffff:c0a8:01ff::ffff:c0a8:01ff 11
::ffff:c0a8:0101::ffff:c0a8:0101 192.168.1.255/24192.168.1.255/24 11
::192.168.1.1/30::192.168.1.1/30 192.168.1.255/24192.168.1.255/24 11

IPv6/IPv4 比较相等的情况 - IP 前缀表示法在 IPv6/IPv4 字符串中指定,作为 ipv6_is_match() 函数的附加参数IPv6/IPv4 comparison equality case- IP-prefix notation specified inside the IPv6/IPv4 strings and as additional argument of the ipv6_is_match() function

datatable(ip1_string:string, ip2_string:string, prefix:long)
[
 // IPv4 are compared as IPv6 addresses 
 '192.168.1.1',    '192.168.1.0',   31, // 31 bit IP4-prefix is used for comparison
 '192.168.1.1/24', '192.168.1.255', 31, // 24 bit IP4-prefix is used for comparison
 '192.168.1.1',    '192.168.1.255', 24, // 24 bit IP4-prefix is used for comparison
   // IPv6 cases
 'fe80::85d:e82c:9446:7994', 'fe80::85d:e82c:9446:7995',     127, // 127 bit IP6-prefix is used for comparison
 'fe80::85d:e82c:9446:7994/127', 'fe80::85d:e82c:9446:7998', 120, // 120 bit IP6-prefix is used for comparison
 'fe80::85d:e82c:9446:7994/120', 'fe80::85d:e82c:9446:7998', 127, // 120 bit IP6-prefix is used for comparison
 // Mixed case of IPv4 and IPv6
 '192.168.1.1/24',   '::ffff:c0a8:01ff', 127, // 127 bit IP6-prefix is used for comparison
 '::ffff:c0a8:0101', '192.168.1.255',    120, // 120 bit IP6-prefix is used for comparison
 '::192.168.1.1/30', '192.168.1.255/24', 127, // 120 bit IP6-prefix is used for comparison
]
| extend result = ipv6_is_match(ip1_string, ip2_string, prefix)
ip1_stringip1_string ip2_stringip2_string 前缀prefix resultresult
192.168.1.1192.168.1.1 192.168.1.0192.168.1.0 3131 11
192.168.1.1/24192.168.1.1/24 192.168.1.255192.168.1.255 3131 11
192.168.1.1192.168.1.1 192.168.1.255192.168.1.255 2424 11
fe80::85d:e82c:9446:7994fe80::85d:e82c:9446:7994 fe80::85d:e82c:9446:7995fe80::85d:e82c:9446:7995 127127 11
fe80::85d:e82c:9446:7994/127fe80::85d:e82c:9446:7994/127 fe80::85d:e82c:9446:7998fe80::85d:e82c:9446:7998 120120 11
fe80::85d:e82c:9446:7994/120fe80::85d:e82c:9446:7994/120 fe80::85d:e82c:9446:7998fe80::85d:e82c:9446:7998 127127 11
192.168.1.1/24192.168.1.1/24 ::ffff:c0a8:01ff::ffff:c0a8:01ff 127127 11
::ffff:c0a8:0101::ffff:c0a8:0101 192.168.1.255192.168.1.255 120120 11
::192.168.1.1/30::192.168.1.1/30 192.168.1.255/24192.168.1.255/24 127127 11