Perform Secure-by-default or Woefully Insecure ‘DNS’ Queries
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

48 lignes
1.2KB

  1. #' Make a DoH Request (POST/wireformat)
  2. #'
  3. #' Issue a `POST` wireformat query of type `type` for `name` to
  4. #' the DoH endpoint specified at `server_path`.
  5. #'
  6. #' @param name name to query for
  7. #' @param type DNS query type (defaults to "`A`")
  8. #' @param server_path full URL path to the DoH server quer endpoint (defaults to Quad9).
  9. #' @return `NULL` (if the query failed) or a `data.frame` (tibble)
  10. #' @references <https://tools.ietf.org/id/draft-ietf-doh-dns-over-https-05.html>
  11. #' @export
  12. #' @examples
  13. #' doh_post("rud.is", "A")
  14. doh_post <- function(name, type = "A", server_path = "https://dns.quad9.net/dns-query") {
  15. DNSRecord$new()$question(
  16. qname = tolower(name[1]),
  17. qtype = toupper(type[1]),
  18. qclass = "IN"
  19. ) -> q
  20. # now, send it off to the server
  21. httr::POST(
  22. url = server_path[1],
  23. httr::add_headers(
  24. `Content-Type` = "application/dns-message",
  25. `Accept` = "application/dns-message"
  26. ),
  27. .CLANDNSTINE_UA,
  28. encode = "raw",
  29. body = q$pack()
  30. ) -> res
  31. httr::stop_for_status(res)
  32. res <- int_dns_wire_to_list(httr::content(res, as = "raw"))
  33. if (length(res)) {
  34. out <- jsonlite::fromJSON(res)
  35. # class(out) <- c("gdns_response", "list")
  36. out
  37. } else {
  38. NULL
  39. }
  40. }