zdns_query: Bulk query using zdns

Description Usage Arguments Value Note Examples

View source: R/zdns-bulk-query.R

Description

Given an entity list and an output file, zdns will be executed and JSON output stored in output_file and an optional log file (if specified).

Usage

1
2
3
zdns_query(entities, input_file = NULL, query_type = "A", output_file,
  num_nameservers = 3000L, num_retries = 3, num_threads = 500,
  log = TRUE, verbose = 3)

Arguments

entities

a character vector of entities to resolve

input_file

if not NULL, overrides entities and this file will be used as the entities source. It must be a plain text file with one entity to resovle per-line. path.expand() will be run on this value.

query_type

anything zdns supports. Presently, one of A, AAAA, ANY, AXFR, CAA, CNAME, DMARC, MX, NS, PTR, TXT, SOA, or SPF (can be lower-case). Default is A.

output_file

path + file to the JSON output. path.expand() will be run on this value.

num_nameservers

total number of nameservers to use. They will be randomly selected from the cached list of valid, public nameservers. It is highly recommended that you refresh this list periodicaly (perhaps daily).

num_retries

how many times should zdns retry query if timeout or temporary failure? Defaults to 3.

num_threads

number of lightweight go threads. Note that the default 500 is smaller than the built-in default of 1000.

log

if TRUE the JSON error log file will be automatically generated and the location printed to the console. If a length 1 character vector, this path + file will be used to save the JSON error log. If FALSE no error log will be captured.

verbose

a value between 1 and 5 indicating the verbosity level. Defaults to 3. Set this to 1 if you're working inside RStudio or other environments that can't handle a great deal of console text since the messages are placed on stdout when log equals FALSE.

Value

value from the system2() call to zdns (invisibly)

Note

if you specified TRUE for log then you are responsible for removing the auto-generated log file.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## Not run: 
# enumerate top prefixes for a domain

c(
  "www", "mail", "mx", "blog", "ns1", "ns2", "dev", "server", "email",
  "cloud", "api", "support", "smtp", "app", "webmail", "test", "box",
  "m", "admin", "forum", "news", "web", "mail2", "ns", "demo", "my",
  "portal", "shop", "host", "cdn", "git", "vps", "mx1", "mail1",
  "static", "help", "ns3", "beta", "chat", "secure", "staging", "vpn",
  "apps", "server1", "ftp", "crm", "new", "wiki",  "home", "info"
) -> top_common_prefixes

tf <- tempfile(fileext = ".json")

zdns_query(
  sprintf("%s.rstudio.com", top_common_prefixes),
  query_type = "A",
  num_nameservers = (length(top_common_prefixes) * 2),
  output_file = tf
)

res <- jsonlite::stream_in(file(tf))

found <- which(lengths(res$data$answers) > 0)

do.call(
  rbind.data.frame,
  lapply(found, function(idx) {
    res$data$answers[[idx]]$query_name <- res$name[idx]
    res$data$answers[[idx]]
  })
) -> xdf

xdf <- xdf[,c("query_name", "name", "class", "ttl", "type", "answer")]

knitr::kable(xdf)

## End(Not run)

hrbrmstr/zdnsr documentation built on Feb. 28, 2020, 9:35 a.m.