ip_to_subnet: Create an IPv4 network from an address and prefix length.

Description Usage Arguments Details Examples

View source: R/ip-to-subnet.R

Description

Given a character vector of IP addresses in CIDR notation (e.g. 1.2.3.4/24) or a character vector of IP addresses and an integer vector of prefix lengths, return a character vector of the network (in CIDR notation).

Usage

1
ip_to_subnet(ip_addresses, prefix_lengths = NULL)

Arguments

ip_addresses

either a character vector of IP addresses in CIDR notation (e.g. 1.2.3.4/24) — in which case prefix_lengths should be NULL — or a character vector of IP addresses — in which case prefix_lengths should be a character vector of the same length as ip_addresses.

prefix_lengths

should be NULL (the default) if ip_addresses is a a character vector of IP addresses in CIDR notation otherwise should be a character vector of the same length as ip_addresses.

Details

Suggested by Slava Nikitin (https://github.com/hrbrmstr/iptools/issues/38).

Examples

1
2
3
4
host_ip <- c("1.2.3.4", "4.3.2.1")
subnet_len <- c(24L, 25L)
ip_to_subnet(host_ip, subnet_len)
ip_to_subnet(c("1.2.3.4/24", "4.3.2.1/25"))

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