ipv4_is_match()ipv4_is_match()

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

ipv4_is_match("127.0.0.1", "127.0.0.1") == true
ipv4_is_match('192.168.1.1', '192.168.1.255') == false
ipv4_is_match('192.168.1.1/24', '192.168.1.255/24') == true
ipv4_is_match('192.168.1.1', '192.168.1.255', 24) == true

语法Syntax

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

参数Arguments

  • Expr1、Expr2:表示 IPv4 地址的字符串表达式。Expr1 , Expr2 : A string expression representing an IPv4 address. 可以使用 IP 前缀表示法对 IPv4 字符串进行掩码操作。IPv4 strings can be masked using IP-prefix notation.
  • PrefixMask:从 0 到 32 的整数,表示所考虑的最有效位的数目。PrefixMask : An integer from 0 to 32 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 到 32)是网络掩码中连续位的数目。The number (1 to 32) to the RIGHT of the slash (/) is the number of contiguous 1 bit in the netmask.

例如,192.168.2.0/24 将具有关联的网络/子网掩码,其中包含 24 个连续位或点分十进制格式的 255.255.255.0。For example, 192.168.2.0/24 will have an associated net/subnetmask containing 24 contiguous bits or 255.255.255.0 in dotted decimal format.

返回Returns

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

示例Examples

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

datatable(ip1_string:string, ip2_string:string)
[
 '192.168.1.0',    '192.168.1.0',       // Equal IPs
 '192.168.1.1/24', '192.168.1.255',     // 24 bit IP-prefix is used for comparison
 '192.168.1.1',    '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 = ipv4_is_match(ip1_string, ip2_string)
ip1_stringip1_string ip2_stringip2_string resultresult
192.168.1.0192.168.1.0 192.168.1.0192.168.1.0 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

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

datatable(ip1_string:string, ip2_string:string, prefix:long)
[
 '192.168.1.1',    '192.168.1.0',   31, // 31 bit IP-prefix is used for comparison
 '192.168.1.1/24', '192.168.1.255', 31, // 24 bit IP-prefix is used for comparison
 '192.168.1.1',    '192.168.1.255', 24, // 24 bit IP-prefix is used for comparison
]
| extend result = ipv4_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