No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

to-inaddr-arpa.R 506B

123456789101112131415161718192021222324
  1. ipv4_regex <-
  2. "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
  3. #' Convert a vector of IPv4 addresses to in-addr.arpa format
  4. #'
  5. #' @md
  6. #' @param ipv4 vector of ipv4 addresses
  7. #' @export
  8. to_inaddr_arpa <- function(ipv4) {
  9. ifelse(
  10. test = grepl(ipv4_regex, ipv4),
  11. yes = paste0(
  12. c(
  13. rev(unlist(strsplit(ipv4, ".", 4), use.names = FALSE)),
  14. "in-addr.arpa."
  15. ),
  16. sep = "",
  17. collapse = "."
  18. ),
  19. no = ipv4
  20. )
  21. }