Browse Source

bulk_query

Bob Rudis 3 years ago
parent
commit
d39ec0442c
6 changed files with 72 additions and 14 deletions
  1. 1
    0
      NAMESPACE
  2. 18
    0
      R/gdns.r
  3. 6
    4
      README.Rmd
  4. 15
    10
      README.md
  5. 25
    0
      man/bulk_query.Rd
  6. 7
    0
      man/query.Rd

+ 1
- 0
NAMESPACE View File

@@ -1,5 +1,6 @@
1 1
 # Generated by roxygen2: do not edit by hand
2 2
 
3
+export(bulk_query)
3 4
 export(query)
4 5
 import(httr)
5 6
 importFrom(jsonlite,fromJSON)

+ 18
- 0
R/gdns.r View File

@@ -14,6 +14,9 @@ S_GET <- purrr::safely(GET)
14 14
 #' security between a client and a recursive resolver, and complements DNSSEC
15 15
 #' to provide end-to-end authenticated DNS lookups.
16 16
 #'
17
+#' To perform vectorized queries with only answers (and no metadata) use
18
+#' \code{bulk_query()}).
19
+#'
17 20
 #' @param name item to lookup. Valid characters are numbers, letters, hyphen, and dot. Length
18 21
 #'        must be between 1 and 255. Names with escaped or non-ASCII characters
19 22
 #'        are not supported. Internationalized domain names must use the
@@ -30,6 +33,7 @@ S_GET <- purrr::safely(GET)
30 33
 #'        approximate network information (usually replacing the last part of
31 34
 #'        your IPv4 address with zeroes).
32 35
 #' @return a \code{list} with the query result or \code{NULL} if an error occurred
36
+#' @references \url{https://developers.google.com/speed/public-dns/docs/dns-over-https}
33 37
 #' @export
34 38
 #' @examples
35 39
 #' query("rud.is")
@@ -48,3 +52,17 @@ query <- function(name, type="1", cd=FALSE, edns_client_subnet=NULL) {
48 52
   }
49 53
 
50 54
 }
55
+
56
+#' Vectorized query, returning only answers in a data frame
57
+#'
58
+#' @param hosts character vector of hosts to query
59
+#' @return \code{data.frame} of only answers (use \code{query()} for detailed responses)
60
+#' @references \url{https://developers.google.com/speed/public-dns/docs/dns-over-https}
61
+#' @export
62
+#' @examples
63
+#' hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com")
64
+#' gdns::bulk_query(hosts)
65
+bulk_query <- function(hosts) {
66
+  results <- map(hosts, gdns::query)
67
+  map_df(results, "Answer")
68
+}

+ 6
- 4
README.Rmd View File

@@ -20,9 +20,12 @@ Traditional DNS queries and responses are sent over UDP or TCP without encryptio
20 20
 
21 21
 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.
22 22
 
23
+More info at <https://developers.google.com/speed/public-dns/docs/dns-over-https>.
24
+
23 25
 The following functions are implemented:
24 26
 
25
-- `query` : perform the DNS query
27
+- `query` : perform Google DNS query for a single host (retreives metadata & answer)
28
+- `bulk_query` : perform bulk host queries, returning a \code{data.frame} of only answers (no metadata)
26 29
 
27 30
 ### News
28 31
 
@@ -60,9 +63,8 @@ test_dir("tests/")
60 63
 
61 64
 library(purrr)
62 65
 
63
-hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com")
64
-results <- map(hosts, gdns::query)
65
-map_df(results, "Answer")
66
+hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com")
67
+gdns::bulk_query(hosts)
66 68
 ```
67 69
 
68 70
 ### Code of Conduct

+ 15
- 10
README.md View File

@@ -5,9 +5,12 @@ Traditional DNS queries and responses are sent over UDP or TCP without encryptio
5 5
 
6 6
 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.
7 7
 
8
+More info at <https://developers.google.com/speed/public-dns/docs/dns-over-https>.
9
+
8 10
 The following functions are implemented:
9 11
 
10
--   `query` : perform the DNS query
12
+-   `query` : perform Google DNS query for a single host (retreives metadata & answer)
13
+-   `bulk_query` : perform bulk host queries, returning a of only answers (no metadata)
11 14
 
12 15
 ### News
13 16
 
@@ -36,7 +39,7 @@ library(gdns)
36 39
 library(testthat)
37 40
 
38 41
 date()
39
-#> [1] "Sat Apr  9 17:16:13 2016"
42
+#> [1] "Sat Apr  9 17:24:33 2016"
40 43
 
41 44
 test_dir("tests/")
42 45
 #> testthat results ========================================================================================================
@@ -49,17 +52,19 @@ library(purrr)
49 52
 #> 
50 53
 #>     is_null
51 54
 
52
-hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com")
53
-results <- map(hosts, gdns::query)
54
-map_df(results, "Answer")
55
-#> Source: local data frame [4 x 4]
55
+hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com")
56
+gdns::bulk_query(hosts)
57
+#> Source: local data frame [7 x 4]
56 58
 #> 
57 59
 #>             name  type   TTL            data
58 60
 #>            (chr) (int) (int)           (chr)
59
-#> 1        rud.is.     1   823 104.236.112.222
60
-#> 2        dds.ec.     1   204   162.243.111.4
61
-#> 3 r-project.org.     1   927   137.208.57.37
62
-#> 4   rstudio.com.     1  3386    45.79.156.36
61
+#> 1        rud.is.     1  3599 104.236.112.222
62
+#> 2        dds.ec.     1   299   162.243.111.4
63
+#> 3 r-project.org.     1  6462   137.208.57.37
64
+#> 4   rstudio.com.     1  3599    45.79.156.36
65
+#> 5     apple.com.     1  2866   17.172.224.47
66
+#> 6     apple.com.     1  2866    17.178.96.59
67
+#> 7     apple.com.     1  2866   17.142.160.59
63 68
 ```
64 69
 
65 70
 ### Code of Conduct

+ 25
- 0
man/bulk_query.Rd View File

@@ -0,0 +1,25 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/gdns.r
3
+\name{bulk_query}
4
+\alias{bulk_query}
5
+\title{Vectorized query, returning only answers in a data frame}
6
+\usage{
7
+bulk_query(hosts)
8
+}
9
+\arguments{
10
+\item{hosts}{character vector of hosts to query}
11
+}
12
+\value{
13
+\code{data.frame} of only answers (use \code{query()} for detailed responses)
14
+}
15
+\description{
16
+Vectorized query, returning only answers in a data frame
17
+}
18
+\examples{
19
+hosts <- c("rud.is", "dds.ec", "r-project.org", "rstudio.com", "apple.com")
20
+gdns::bulk_query(hosts)
21
+}
22
+\references{
23
+\url{https://developers.google.com/speed/public-dns/docs/dns-over-https}
24
+}
25
+

+ 7
- 0
man/query.Rd View File

@@ -41,7 +41,14 @@ encrypted HTTPS connection. DNS-over-HTTPS greatly enhances privacy and
41 41
 security between a client and a recursive resolver, and complements DNSSEC
42 42
 to provide end-to-end authenticated DNS lookups.
43 43
 }
44
+\details{
45
+To perform vectorized queries with only answers (and no metadata) use
46
+\code{bulk_query()}).
47
+}
44 48
 \examples{
45 49
 query("rud.is")
46 50
 }
51
+\references{
52
+\url{https://developers.google.com/speed/public-dns/docs/dns-over-https}
53
+}
47 54
 

Loading…
Cancel
Save