ipv4_is_match()
Learn how to use the ipv4_is_match() function to match two IPv4 strings.
Matches two IPv4 strings. The two IPv4 strings are parsed and compared while accounting for the combined IP-prefix mask calculated from argument prefixes, and the optional prefix argument.
Syntax
ipv4_is_match(ip1,ip2[ ,prefix])
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| ip1, ip2 | string | ✔️ | An expression representing an IPv4 address. IPv4 strings can be masked using IP-prefix notation. |
| prefix | int | An integer from 0 to 32 representing the number of most-significant bits that are taken into account. |
Returns
true: If the long representation of the first IPv4 string argument is equal to the second IPv4 string argument.false: Otherwise.null: If conversion for one of the two IPv4 strings wasn’t successful.
Examples
Simple example
print ipv4_is_match('192.168.1.1/24', '192.168.1.255')
Output
| print_0 |
|---|
| true |
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)
Output
| ip1_string | ip2_string | result |
|---|---|---|
| 192.168.1.0 | 192.168.1.0 | true |
| 192.168.1.1/24 | 192.168.1.255 | true |
| 192.168.1.1 | 192.168.1.255/24 | true |
| 192.168.1.1/30 | 192.168.1.255/24 | true |
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)
Output
| ip1_string | ip2_string | prefix | result |
|---|---|---|---|
| 192.168.1.1 | 192.168.1.0 | 31 | true |
| 192.168.1.1/24 | 192.168.1.255 | 31 | true |
| 192.168.1.1 | 192.168.1.255 | 24 | true |
Related content
- Overview of IPv4/IPv6 functions
- Overview of IPv4 text match functions
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.