# construct from character vector
ip_network(c("192.168.0.0/24", "2001:db8::/48"))
# validates inputs and replaces with NA
ip_network(c("192.168.0.0/33", "192.168.0.0"))
# IP networks should not have any host bits set
ip_network("192.168.0.1/22")
# but we can mask the host bits if desired
ip_network("192.168.0.1/22", strict = FALSE)
# construct from address + prefix length
ip_network(ip_address("192.168.0.0"), 24L)
# construct from address + netmask
ip_network(ip_address("192.168.0.0"), prefix_length(ip_address("255.255.255.0")))
# construct from address + hostmask
ip_network(ip_address("192.168.0.0"), prefix_length(ip_address("0.0.0.255")))
Run the code above in your browser using DataLab