diff --git a/NAMESPACE b/NAMESPACE index 6940d3b..041715e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(bulk_query) export(query) import(httr) importFrom(jsonlite,fromJSON) diff --git a/R/gdns.r b/R/gdns.r index bcb48b9..8746478 100644 --- a/R/gdns.r +++ b/R/gdns.r @@ -14,6 +14,9 @@ S_GET <- purrr::safely(GET) #' security between a client and a recursive resolver, and complements DNSSEC #' to provide end-to-end authenticated DNS lookups. #' +#' To perform vectorized queries with only answers (and no metadata) use +#' \code{bulk_query()}). +#' #' @param name item to lookup. Valid characters are numbers, letters, hyphen, and dot. Length #' must be between 1 and 255. Names with escaped or non-ASCII characters #' are not supported. Internationalized domain names must use the @@ -30,6 +33,7 @@ S_GET <- purrr::safely(GET) #' approximate network information (usually replacing the last part of #' your IPv4 address with zeroes). #' @return a \code{list} with the query result or \code{NULL} if an error occurred +#' @references \url{https://developers.google.com/speed/public-dns/docs/dns-over-https} #' @export #' @examples #' query("rud.is") @@ -48,3 +52,17 @@ query <- function(name, type="1", cd=FALSE, edns_client_subnet=NULL) { } } + +#' Vectorized query, returning only answers in a data frame +#' +#' @param hosts character vector of hosts to query +#' @return \code{data.frame} of only answers (use \code{query()} for detailed responses) +#' @references \url{https://developers.google.com/speed/public-dns/docs/dns-over-https} +#' @export +#' @examples +#' hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com") +#' gdns::bulk_query(hosts) +bulk_query <- function(hosts) { + results <- map(hosts, gdns::query) + map_df(results, "Answer") +} diff --git a/README.Rmd b/README.Rmd index e98ca38..d6cdf7a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -20,9 +20,12 @@ Traditional DNS queries and responses are sent over UDP or TCP without encryptio To address this problem, Google Public DNS offers DNS resolution over an encrypted HTTPS connection. DNS-over-HTTPS greatly enhances privacy and security between a client and a recursive resolver, and complements DNSSEC to provide end-to-end authenticated DNS lookups. +More info at . + The following functions are implemented: -- `query` : perform the DNS query +- `query` : perform Google DNS query for a single host (retreives metadata & answer) +- `bulk_query` : perform bulk host queries, returning a \code{data.frame} of only answers (no metadata) ### News @@ -60,9 +63,8 @@ test_dir("tests/") library(purrr) -hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com") -results <- map(hosts, gdns::query) -map_df(results, "Answer") +hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com") +gdns::bulk_query(hosts) ``` ### Code of Conduct diff --git a/README.md b/README.md index d044042..fa1e8f6 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,12 @@ Traditional DNS queries and responses are sent over UDP or TCP without encryptio To address this problem, Google Public DNS offers DNS resolution over an encrypted HTTPS connection. DNS-over-HTTPS greatly enhances privacy and security between a client and a recursive resolver, and complements DNSSEC to provide end-to-end authenticated DNS lookups. +More info at . + The following functions are implemented: -- `query` : perform the DNS query +- `query` : perform Google DNS query for a single host (retreives metadata & answer) +- `bulk_query` : perform bulk host queries, returning a of only answers (no metadata) ### News @@ -36,7 +39,7 @@ library(gdns) library(testthat) date() -#> [1] "Sat Apr 9 17:16:13 2016" +#> [1] "Sat Apr 9 17:24:33 2016" test_dir("tests/") #> testthat results ======================================================================================================== @@ -49,17 +52,19 @@ library(purrr) #> #> is_null -hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com") -results <- map(hosts, gdns::query) -map_df(results, "Answer") -#> Source: local data frame [4 x 4] +hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com") +gdns::bulk_query(hosts) +#> Source: local data frame [7 x 4] #> #> name type TTL data #> (chr) (int) (int) (chr) -#> 1 rud.is. 1 823 104.236.112.222 -#> 2 dds.ec. 1 204 162.243.111.4 -#> 3 r-project.org. 1 927 137.208.57.37 -#> 4 rstudio.com. 1 3386 45.79.156.36 +#> 1 rud.is. 1 3599 104.236.112.222 +#> 2 dds.ec. 1 299 162.243.111.4 +#> 3 r-project.org. 1 6462 137.208.57.37 +#> 4 rstudio.com. 1 3599 45.79.156.36 +#> 5 apple.com. 1 2866 17.172.224.47 +#> 6 apple.com. 1 2866 17.178.96.59 +#> 7 apple.com. 1 2866 17.142.160.59 ``` ### Code of Conduct diff --git a/man/bulk_query.Rd b/man/bulk_query.Rd new file mode 100644 index 0000000..1b202c2 --- /dev/null +++ b/man/bulk_query.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gdns.r +\name{bulk_query} +\alias{bulk_query} +\title{Vectorized query, returning only answers in a data frame} +\usage{ +bulk_query(hosts) +} +\arguments{ +\item{hosts}{character vector of hosts to query} +} +\value{ +\code{data.frame} of only answers (use \code{query()} for detailed responses) +} +\description{ +Vectorized query, returning only answers in a data frame +} +\examples{ +hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com") +gdns::bulk_query(hosts) +} +\references{ +\url{https://developers.google.com/speed/public-dns/docs/dns-over-https} +} + diff --git a/man/query.Rd b/man/query.Rd index deeb6bd..bd78d2f 100644 --- a/man/query.Rd +++ b/man/query.Rd @@ -41,7 +41,14 @@ encrypted HTTPS connection. DNS-over-HTTPS greatly enhances privacy and security between a client and a recursive resolver, and complements DNSSEC to provide end-to-end authenticated DNS lookups. } +\details{ +To perform vectorized queries with only answers (and no metadata) use +\code{bulk_query()}). +} \examples{ query("rud.is") } +\references{ +\url{https://developers.google.com/speed/public-dns/docs/dns-over-https} +}