mirror of https://gitlab.com/hrbrmstr/playdoh.git
boB Rudis
5 years ago
10 changed files with 278 additions and 9 deletions
@ -1,4 +1,6 @@ |
|||||
# Generated by roxygen2: do not edit by hand |
# Generated by roxygen2: do not edit by hand |
||||
|
|
||||
|
export(doh_post) |
||||
import(httr) |
import(httr) |
||||
|
import(reticulate) |
||||
importFrom(jsonlite,fromJSON) |
importFrom(jsonlite,fromJSON) |
||||
|
@ -0,0 +1,69 @@ |
|||||
|
#' Make a POST DoH Request (wireformat) |
||||
|
#' |
||||
|
#' Issue the query of type `type` for `name` to the DoH endpoint specified at `server_path`. |
||||
|
#' |
||||
|
#' @param name name to query for |
||||
|
#' @param type DNS query type (defaults to "`A`") |
||||
|
#' @param server_path full URL path to the DoH server quer endpoint (defaults to Quad9). |
||||
|
#' @return `NULL` (if the query failed) or a `data.frame` (tibble) |
||||
|
#' @export |
||||
|
doh_post <- function(name, type = "A", server_path = "https://dns.quad9.net/dns-query") { |
||||
|
|
||||
|
# for now, use python's {dnslib} as a crutch to |
||||
|
# encode/decode wireformat DNS questions and answers |
||||
|
|
||||
|
.dns$DNSRecord$question( |
||||
|
qname = tolower(name[1]), |
||||
|
qtype = toupper(type[1]), |
||||
|
qclass = "IN" |
||||
|
) -> q |
||||
|
|
||||
|
qpak <- q$pack() |
||||
|
|
||||
|
# now, send it off to the server |
||||
|
|
||||
|
httr::POST( |
||||
|
url = server_path[1], |
||||
|
httr::add_headers( |
||||
|
`Content-Type` = "application/dns-message", |
||||
|
`Accept` = "application/dns-message" |
||||
|
), |
||||
|
encode = "raw", |
||||
|
body = qpak |
||||
|
) -> res |
||||
|
|
||||
|
httr::warn_for_status(res) |
||||
|
|
||||
|
# if the response is OK, make it a data frame |
||||
|
|
||||
|
if (httr::status_code(res) == 200) { |
||||
|
|
||||
|
r <- .dns$DNSRecord$parse(httr::content(res)) |
||||
|
|
||||
|
q <- r$get_q() |
||||
|
|
||||
|
do.call( |
||||
|
rbind.data.frame, |
||||
|
lapply(r$rr, function(.x) { |
||||
|
data.frame( |
||||
|
query = py_str(q$qname), |
||||
|
qtype = q$qtype, |
||||
|
rname = py_str(.x$rname), |
||||
|
rtype = .x$rtype, |
||||
|
rdata = py_str(.x$rdata), |
||||
|
ttl = .x$ttl, |
||||
|
stringsAsFactors = FALSE |
||||
|
) |
||||
|
}) |
||||
|
|
||||
|
) -> xdf |
||||
|
|
||||
|
class(xdf) <- c("tbl_df", "tbl", "data.frame") |
||||
|
|
||||
|
xdf |
||||
|
|
||||
|
} else { |
||||
|
NULL |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
list( |
||||
|
google = list( |
||||
|
url = "https://dns.google.com/experimental", |
||||
|
extra_params = list() |
||||
|
), |
||||
|
cloudflare = list( |
||||
|
url = "https://cloudflare-dns.com/dns-query", |
||||
|
extra_params = list( |
||||
|
cd = "false", |
||||
|
do = "true", |
||||
|
ct = "application/dns-json" |
||||
|
) |
||||
|
), |
||||
|
quad9 = list( |
||||
|
url = "https://dns.quad9.net/dns-query", |
||||
|
extra_params = list() |
||||
|
), |
||||
|
securedns_eu = list( |
||||
|
url = "https://doh.securedns.eu/dns-query", |
||||
|
extra_params = list( |
||||
|
edns_client_subnet = NULL |
||||
|
) |
||||
|
), |
||||
|
dnswarden_adblock = list( |
||||
|
url = "https://doh.dnswarden.com/adblock", |
||||
|
extra_params = list() |
||||
|
), |
||||
|
dnswarden_uncensored = list( |
||||
|
url = "https://doh.dnswarden.com/uncensored", |
||||
|
extra_params = list() |
||||
|
), |
||||
|
cleanbrowsing_security = list( |
||||
|
url = "https://doh.cleanbrowsing.org/doh/security-filter/", |
||||
|
extra_params = list(cd = "false") |
||||
|
), |
||||
|
cleanbrowsing_family = list( |
||||
|
url = "https://doh.cleanbrowsing.org/doh/family-filter/", |
||||
|
extra_params = list() |
||||
|
), |
||||
|
cleanbrowsing_adult = list( |
||||
|
url = "https://doh.cleanbrowsing.org/doh/adult-filter/", |
||||
|
extra_params = list() |
||||
|
), |
||||
|
power_dns = list( |
||||
|
url = "https://doh.powerdns.org", |
||||
|
extra_params = list() |
||||
|
), |
||||
|
appliedprivacy = list( |
||||
|
url = "https://doh.appliedprivacy.net/query", |
||||
|
extra_params = list() |
||||
|
) |
||||
|
) -> doh_servers |
@ -1,12 +1,13 @@ |
|||||
#' ... |
#' Make 'DNS over HTTPS' Queries |
||||
#' |
#' |
||||
#' - URL: <https://gitlab.com/hrbrmstr/playdoh> |
#' - URL: <https://gitlab.com/hrbrmstr/playdoh> |
||||
#' - BugReports: <https://gitlab.com/hrbrmstr/playdoh/issues> |
#' - BugReports: <https://gitlab.com/hrbrmstr/playdoh/issues> |
||||
#' |
#' |
||||
#' @md |
#' @md |
||||
#' @name playdoh |
#' @name playdoh |
||||
#' @docType package |
#' @docType package |
||||
|
#' @keywords internal |
||||
#' @author Bob Rudis (bob@@rud.is) |
#' @author Bob Rudis (bob@@rud.is) |
||||
#' @import httr |
#' @import httr reticulate |
||||
#' @importFrom jsonlite fromJSON |
#' @importFrom jsonlite fromJSON |
||||
NULL |
NULL |
||||
|
@ -0,0 +1,29 @@ |
|||||
|
py_c <- reticulate::py_config() |
||||
|
|
||||
|
.dns <- NULL |
||||
|
|
||||
|
.onLoad <- function(libname, pkgname) { |
||||
|
|
||||
|
if (utils::compareVersion(py_c$version, "3.5") < 0) { |
||||
|
stop( |
||||
|
paste0( |
||||
|
c( |
||||
|
"Python 3.5+ is required. If this is installed please set RETICULATE_PYTHON ", |
||||
|
"to the path to the Python 3 binary on your system and try re-installing/", |
||||
|
"re-loading the package." |
||||
|
), |
||||
|
collapse = "" |
||||
|
) |
||||
|
) |
||||
|
return() |
||||
|
} |
||||
|
|
||||
|
if (!reticulate::py_module_available("dnslib")) { |
||||
|
packageStartupMessage( |
||||
|
"The 'dnslib' Python module must be installed." |
||||
|
) |
||||
|
} else { |
||||
|
.dns <<- reticulate::import("dnslib", delay_load = TRUE) |
||||
|
} |
||||
|
|
||||
|
} |
@ -1,2 +1,79 @@ |
|||||
|
|
||||
|
[![Travis-CI Build |
||||
|
Status](https://travis-ci.org/hrbrmstr/playdoh.svg?branch=master)](https://travis-ci.org/hrbrmstr/playdoh) |
||||
|
[![Coverage |
||||
|
Status](https://codecov.io/gh/hrbrmstr/playdoh/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/playdoh) |
||||
|
[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/playdoh)](https://cran.r-project.org/package=playdoh) |
||||
|
|
||||
# playdoh |
# playdoh |
||||
|
|
||||
|
Make ‘DNS over HTTPS’ Queries |
||||
|
|
||||
|
## Description |
||||
|
|
||||
|
Make ‘DNS over HTTPS’ Queries |
||||
|
|
||||
|
## What’s Inside The Tin |
||||
|
|
||||
|
The following functions are implemented: |
||||
|
|
||||
|
- `doh_post`: Make a POST DoH Request (wireformat) |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
``` r |
||||
|
devtools::install_git("https://sr.ht.com/~hrbrmstr/playdoh.git") |
||||
|
# or |
||||
|
devtools::install_gitlab("hrbrmstr/playdoh.git") |
||||
|
# or (if you must) |
||||
|
devtools::install_github("hrbrmstr/playdoh") |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
``` r |
||||
|
library(playdoh) |
||||
|
library(tidyverse) # for printing |
||||
|
|
||||
|
# current version |
||||
|
packageVersion("playdoh") |
||||
|
## [1] '0.1.0' |
||||
|
``` |
||||
|
|
||||
|
### Basic functionality |
||||
|
|
||||
|
``` r |
||||
|
doh_post("rud.is") |
||||
|
## # A tibble: 1 x 6 |
||||
|
## query qtype rname rtype rdata ttl |
||||
|
## <chr> <int> <chr> <int> <chr> <int> |
||||
|
## 1 rud.is. 1 rud.is. 1 172.93.49.183 3572 |
||||
|
|
||||
|
doh_post("lenovo.com", "txt") |
||||
|
## # A tibble: 10 x 6 |
||||
|
## query qtype rname rtype rdata ttl |
||||
|
## <chr> <int> <chr> <int> <chr> <int> |
||||
|
## 1 lenovo.co… 16 lenovo.co… 16 "\"google-site-verification=nGgukcp60rC-gFxMOJw1NHH0B4VnSchRrlfWV-He_tE\"" 7173 |
||||
|
## 2 lenovo.co… 16 lenovo.co… 16 "\"a82c74b37aa84e7c8580f0e32f4d795d\"" 7173 |
||||
|
## 3 lenovo.co… 16 lenovo.co… 16 "\"google-site-verification=sHIlSlj0U6UnCDkfHp1AolWgVEvDjWvc0TR4KaysD2c\"" 7173 |
||||
|
## 4 lenovo.co… 16 lenovo.co… 16 "\"v=spf1 include:spf.messagelabs.com include:_netblocks.eloqua.com ~all\"" 7173 |
||||
|
## 5 lenovo.co… 16 lenovo.co… 16 "\"qh7hdmqm4lzs85p704d6wsybgrpsly0j\"" 7173 |
||||
|
## 6 lenovo.co… 16 lenovo.co… 16 "\"ece42d7743c84d6889abda7011fe6f53\"" 7173 |
||||
|
## 7 lenovo.co… 16 lenovo.co… 16 "\"iHzQJvsKnyGP2Nm2qBgL3fyBJ0CC9z4GkY/flfk4EzLP8lPxWHDDPKqZWm1TkeF5kEIL+NotY… 7173 |
||||
|
## 8 lenovo.co… 16 lenovo.co… 16 "\"Visit www.lenovo.com/think for information about Lenovo products and serv… 7173 |
||||
|
## 9 lenovo.co… 16 lenovo.co… 16 "\"google-site-verification=VxW_e6r_Ka7A518qfX2MmIMHGnkpGbnACsjSxKFCBw0\"" 7173 |
||||
|
## 10 lenovo.co… 16 lenovo.co… 16 "\"facebook-domain-verification=1r2am7c2bhzrxpqyt0mda0djoquqsi\"" 7173 |
||||
|
``` |
||||
|
|
||||
|
## playdoh Metrics |
||||
|
|
||||
|
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | |
||||
|
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: | |
||||
|
| R | 6 | 0.86 | 122 | 0.92 | 23 | 0.52 | 26 | 0.43 | |
||||
|
| Rmd | 1 | 0.14 | 11 | 0.08 | 21 | 0.48 | 35 | 0.57 | |
||||
|
|
||||
|
## Code of Conduct |
||||
|
|
||||
|
Please note that this project is released with a [Contributor Code of |
||||
|
Conduct](CONDUCT.md). By participating in this project you agree to |
||||
|
abide by its terms. |
||||
|
@ -0,0 +1,22 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/doh-post.R |
||||
|
\name{doh_post} |
||||
|
\alias{doh_post} |
||||
|
\title{Make a POST DoH Request (wireformat)} |
||||
|
\usage{ |
||||
|
doh_post(name, type = "A", |
||||
|
server_path = "https://dns.quad9.net/dns-query") |
||||
|
} |
||||
|
\arguments{ |
||||
|
\item{name}{name to query for} |
||||
|
|
||||
|
\item{type}{DNS query type (defaults to "\code{A}")} |
||||
|
|
||||
|
\item{server_path}{full URL path to the DoH server quer endpoint (defaults to Quad9).} |
||||
|
} |
||||
|
\value{ |
||||
|
\code{NULL} (if the query failed) or a \code{data.frame} (tibble) |
||||
|
} |
||||
|
\description{ |
||||
|
Issue the query of type \code{type} for \code{name} to the DoH endpoint specified at \code{server_path}. |
||||
|
} |
Loading…
Reference in new issue