cidr_match

Table of Contents

Function

cidr_match — test if IP is in a network

Synopsis

cidr_match(network: net, val: any) -> bool

Description

The cidr_match function returns true if val contains an IP address that falls within the network given by network. When val is a complex type, the function traverses its nested structure to find any ip values. If network is not type net, then an error is returned.

Examples

Test whether values are IP addresses in a network:

yield cidr_match(10.0.0.0/8, this)
10.1.2.129
11.1.2.129
10
"foo"
Loading...

It also works for IPs in complex values:

yield cidr_match(10.0.0.0/8, this)
[10.1.2.129,11.1.2.129]
{a:10.0.0.1}
{a:11.0.0.1}
Loading...

The first argument must be a network:

yield cidr_match([1,2,3], this)
10.0.0.1
Loading...
Next: coalesce

SuperDB