cidr_match — test if IP is in a network
cidr_match(network: net, val: any) -> bool
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.
Test whether values are IP addresses in a network:
echo '10.1.2.129 11.1.2.129 10 "foo"' | zq -z 'yield cidr_match(10.0.0.0/8, this)' -
=>
true
false
false
false
It also works for IPs in complex values:
echo '[10.1.2.129,11.1.2.129] {a:10.0.0.1} {a:11.0.0.1}' | zq -z 'yield cidr_match(10.0.0.0/8, this)' -
=>
true
true
false
The first argument must be a network:
echo '10.0.0.1' | zq -z 'yield cidr_match([1,2,3], this)' -
=>
error({message:"cidr_match: not a net",on:[1,2,3]})