ip_in_any: check if IP address falls within any of the ranges specified

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

ip_in_any checks whether a vector of IP addresses fall within any of the speficied ranges.

Usage

1
ip_in_any(ip_addresses, ranges)

Arguments

ip_addresses

character vector of IP addresses

ranges

character vector of CIDR reanges

Value

a logical vector of whether a given IP was in any of the ranges

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## Not run: 
north_america <- unlist(country_ranges(countries=c("US", "CA", "MX")))
germany <- unlist(country_ranges("DE"))

set.seed(1492)
targets <- ip_random(1000)

for_sure <- range_generate(sample(north_america, 1))
all(ip_in_any(for_sure, north_america)) # shld be TRUE
## [1] TRUE

absolutely_not <- range_generate(sample(germany, 1))
any(ip_in_any(absolutely_not, north_america)) # shld be FALSE
## [1] FALSE

who_knows_na <- ip_in_any(targets, north_america)
who_knows_de <- ip_in_any(targets, germany)

sum(who_knows_na)
## [1] 464

sum(who_knows_de)
## [1] 43

## End(Not run)

iptools documentation built on Sept. 10, 2021, 5:06 p.m.