Tools to work with the Google DNS over HTTPS API in R https://cinc.rud.is/web/packages/gdns/
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.

zbulk-query.R 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #' Vectorized query, returning only answers in a data frame
  2. #'
  3. #' @param entities character vector of entities to query
  4. #' @param type RR type can be represented as a number in [1, 65535] or canonical
  5. #' string (A, aaaa, etc). More information on RR types can be
  6. #' found \href{http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4}{here}.
  7. #' @param cd (Checking Disabled) flag. Use `TRUE` to disable DNSSEC validation;
  8. #' Default: `FALSE`.
  9. #' @param do (DNSSEC OK) flag. Use `TRUE` include DNSSEC records (RRSIG, NSEC, NSEC3);
  10. #' Default: `FALSE`.
  11. #' @param edns_client_subnet The edns0-client-subnet option. Format is an IP
  12. #' address with a subnet mask. Examples: \code{1.2.3.4/24},
  13. #' \code{2001:700:300::/48}.\cr
  14. #' If you are using DNS-over-HTTPS because of privacy concerns, and do
  15. #' not want any part of your IP address to be sent to authoritative
  16. #' nameservers for geographic location accuracy, use
  17. #' \code{edns_client_subnet=0.0.0.0/0}. Google Public DNS normally sends
  18. #' approximate network information (usually replacing the last part of
  19. #' your IPv4 address with zeroes). \code{0.0.0.0/0} is the default.
  20. #' @return \code{data.frame} of only answers (use \code{query()} for detailed responses)
  21. #' @references \url{https://developers.google.com/speed/public-dns/docs/dns-over-https}
  22. #' @export
  23. #' @note this is a fairly naive function. It expects \code{Answer} to be one of the
  24. #' return value list slots. The intent for it was to make it easier
  25. #' to do bulk forward queries. It will get smarter in future versions.
  26. #' @examples
  27. #' hosts <- c("rud.is", "r-project.org", "rstudio.com", "apple.com")
  28. #' gdns::bulk_query(hosts)
  29. bulk_query <- function(entities, type = 1, cd = FALSE, do = FALSE,
  30. edns_client_subnet = "0.0.0.0/0") {
  31. lapply(
  32. entities,
  33. query, type = type, cd = cd,
  34. edns_client_subnet = edns_client_subnet
  35. ) -> results
  36. lapply(seq_along(results), function(idx) {
  37. res <- as.data.frame(results[[idx]])
  38. res$entity <- entities[[idx]]
  39. res
  40. }) -> xlst
  41. xdf <- do.call(rbind.data.frame, xlst)
  42. class(xdf) <- c("tbl_df", "tbl", "data.frame")
  43. xdf
  44. }