Browse Source

all endpoints coded; some need IPv6 suport; all need tests

master
boB Rudis 4 years ago
parent
commit
020dcb556c
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 7
      NAMESPACE
  2. 25
      R/as-info.R
  3. 27
      R/asn-networks.R
  4. 49
      R/domains-in-network.R
  5. 27
      R/domains-on-ip.R
  6. 25
      R/ip-for-domain.R
  7. 25
      R/ip-geo.R
  8. 25
      R/ip-info.R
  9. 4
      R/org-networks.R
  10. 23
      README.md
  11. 16
      man/asn_info.Rd
  12. 18
      man/asn_nets.Rd
  13. 24
      man/domains_in_network.Rd
  14. 18
      man/domains_on_ip.Rd
  15. 16
      man/ip_geo.Rd
  16. 16
      man/ip_info.Rd
  17. 16
      man/ips_for_domain.Rd
  18. 7
      man/org_networks.Rd

7
NAMESPACE

@ -1,5 +1,12 @@
# Generated by roxygen2: do not edit by hand
export(asn_info)
export(asn_nets)
export(domains_in_network)
export(domains_on_ip)
export(ip_geo)
export(ip_info)
export(ips_for_domain)
export(networksdb_api_key)
export(org_info)
export(org_networks)

25
R/as-info.R

@ -0,0 +1,25 @@
#' Search for an autonomous system
#'
#' @param asn the autonomous system number
#' @param api_key see [networksdb_api_key()]
#' @export
asn_info <- function(asn, api_key = networksdb_api_key()) { # ipv6
httr::GET(
url = "https://networksdb.io/api/asn-info",
query = list(
asn = asn[1],
),
httr::add_headers(`X-Api-Key` = api_key),
.NETWORKS_DB_UA
) -> res
httr::stop_for_status(res)
out <- httr::content(res, as = "text", encoding = "UTF-8")
out <- jsonlite::fromJSON(out)
out
}

27
R/asn-networks.R

@ -0,0 +1,27 @@
#' Search for the networks announced by an autonomous system
#'
#' @param asn the autonomous system number
#' @param page results pagination
#' @param api_key see [networksdb_api_key()]
#' @export
asn_nets <- function(asn, page = 1, api_key = networksdb_api_key()) { # ipv6
httr::GET(
url = "https://networksdb.io/api/asn-networks",
query = list(
asn = asn[1],
page = as.integer(page[1])
),
httr::add_headers(`X-Api-Key` = api_key),
.NETWORKS_DB_UA
) -> res
httr::stop_for_status(res)
out <- httr::content(res, as = "text", encoding = "UTF-8")
out <- jsonlite::fromJSON(out)
out
}

49
R/domains-in-network.R

@ -0,0 +1,49 @@
#' Perform a "mass" reverse DNS lookup to find all the domain names pointing to any IPv4 or IPv6 address in the given network
#'
#' @param ip_start,ip_end,cidr Either use `ip_start` and `ip_end` OR `cidr`;
#' @param page results pagination
#' @param api_key see [networksdb_api_key()]
#' @export
domains_in_network <- function(ip_start, ip_end, cidr, page = 1, api_key = networksdb_api_key()) {
if (missing(cidr)) {
if (!all(c(!missing(ip_start)), (!missing(ip_end)))) {
stop("If `cidr` is missing, both `ip_start` and `ip_end` are required.", call.=FALSE)
}
params <- list(
ip_start = ip_start[1],
ip_end = ip_end[1]
)
} else {
if (!all(c(missing(ip_start)), (missing(ip_end)))) {
stop("If `cidr` is present, both `ip_start` and `ip_end` should not be used.", call.=FALSE)
}
params <- list(
cidr = cidr[1]
)
}
params$page <- as.integer(page[1])
httr::GET(
url = "https://networksdb.io/api/mass-reverse-dns",
query = params,
httr::add_headers(`X-Api-Key` = api_key),
.NETWORKS_DB_UA
) -> res
httr::stop_for_status(res)
out <- httr::content(res, as = "text", encoding = "UTF-8")
out <- jsonlite::fromJSON(out)
out
}

27
R/domains-on-ip.R

@ -0,0 +1,27 @@
#' Perform a reverse DNS lookup to find all the domain names pointing to the given IPv4 or IPv6 address
#'
#' @param ip address to lookup
#' @param page pagination
#' @param api_key see [networksdb_api_key()]
#' @export
domains_on_ip <- function(ip, page = 1, api_key = networksdb_api_key()) { # ipv6
httr::GET(
url = "https://networksdb.io/api/reverse-dns",
query = list(
ip = ip[1],
page = as.integer(page[1])
),
httr::add_headers(`X-Api-Key` = api_key),
.NETWORKS_DB_UA
) -> res
httr::stop_for_status(res)
out <- httr::content(res, as = "text", encoding = "UTF-8")
out <- jsonlite::fromJSON(out)
out
}

25
R/ip-for-domain.R

@ -0,0 +1,25 @@
#' Perform a forward DNS lookup to find all the IPv4 and IPv6 addresses pointed to by a given domain name
#'
#' @param domain domain to lookup
#' @param api_key see [networksdb_api_key()]
#' @export
ips_for_domain <- function(domain, api_key = networksdb_api_key()) { # ipv6
httr::GET(
url = "https://networksdb.io/api/dns",
query = list(
domain = domain[1],
),
httr::add_headers(`X-Api-Key` = api_key),
.NETWORKS_DB_UA
) -> res
httr::stop_for_status(res)
out <- httr::content(res, as = "text", encoding = "UTF-8")
out <- jsonlite::fromJSON(out)
out
}

25
R/ip-geo.R

@ -0,0 +1,25 @@
#' Request geolocation information for a given IPv4 or IPv6 Address.
#'
#' @param ip IPv4 or IPv6 address
#' @param api_key see [networksdb_api_key()]
#' @export
ip_geo <- function(ip, api_key = networksdb_api_key()) { # ipv6
httr::GET(
url = "https://networksdb.io/api/ip-geo",
query = list(
ip = ip[1],
),
httr::add_headers(`X-Api-Key` = api_key),
.NETWORKS_DB_UA
) -> res
httr::stop_for_status(res)
out <- httr::content(res, as = "text", encoding = "UTF-8")
out <- jsonlite::fromJSON(out)
out
}

25
R/ip-info.R

@ -0,0 +1,25 @@
#' Search for an IPv4 or IPv6 address
#'
#' @param ip IPv4 or IPv6 address
#' @param api_key see [networksdb_api_key()]
#' @export
ip_info <- function(ip, api_key = networksdb_api_key()) { # ipv6
httr::GET(
url = "https://networksdb.io/api/ip-info",
query = list(
ip = ip[1],
),
httr::add_headers(`X-Api-Key` = api_key),
.NETWORKS_DB_UA
) -> res
httr::stop_for_status(res)
out <- httr::content(res, as = "text", encoding = "UTF-8")
out <- jsonlite::fromJSON(out)
out
}

4
R/org-networks.R

@ -1,7 +1,11 @@
#' Search for the public networks owned by an organisation.
#'
#' @param id id of an organisation (i.e. returned by [org_search()])
#' @param page results pagination; see `return`
#' @param api_key see [networksdb_api_key()]
#' @return `list` with `total` (# of results for the search), `page` (the current page number), and
#' `results` which is a data frame of search results. if `nrow()` of this data frame is >
#' `total` then there are more pages available.
#' @export
org_networks <- function(id, page = 1, api_key = networksdb_api_key()) { # ipv6

23
README.md

@ -28,6 +28,19 @@ NetworksDB API.
The following functions are implemented:
- `asn_info`: Search for an autonomous system
- `asn_nets`: Search for the networks announced by an autonomous
system
- `domains_in_network`: Perform a “mass” reverse DNS lookup to find
all the domain names pointing to any IPv4 or IPv6 address in the
given network
- `domains_on_ip`: Perform a reverse DNS lookup to find all the domain
names pointing to the given IPv4 or IPv6 address
- `ip_geo`: Request geolocation information for a given IPv4 or IPv6
Address.
- `ip_info`: Search for an IPv4 or IPv6 address
- `ips_for_domain`: Perform a forward DNS lookup to find all the IPv4
and IPv6 addresses pointed to by a given domain name
- `networksdb_api_key`: Get or set NetworksDB Personal Access Token
- `org_info`: Retreive information about an organisation.
- `org_networks`: Search for the public networks owned by an
@ -43,6 +56,8 @@ remotes::install_git("https://git.sr.ht/~hrbrmstr/networksdb")
# or
remotes::install_gitlab("hrbrmstr/networksdb")
# or
remotes::install_bitbucket("hrbrmstr/networksdb")
# or
remotes::install_github("hrbrmstr/networksdb")
```
@ -61,10 +76,10 @@ packageVersion("networksdb")
## networksdb Metrics
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | --: | ----------: | ---: | -------: | ---: |
| R | 7 | 0.88 | 72 | 0.9 | 27 | 0.64 | 41 | 0.59 |
| Rmd | 1 | 0.12 | 8 | 0.1 | 15 | 0.36 | 28 | 0.41 |
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 14 | 0.93 | 187 | 0.96 | 77 | 0.84 | 83 | 0.75 |
| Rmd | 1 | 0.07 | 8 | 0.04 | 15 | 0.16 | 28 | 0.25 |
## Code of Conduct

16
man/asn_info.Rd

@ -0,0 +1,16 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as-info.R
\name{asn_info}
\alias{asn_info}
\title{Search for an autonomous system}
\usage{
asn_info(asn, api_key = networksdb_api_key())
}
\arguments{
\item{asn}{the autonomous system number}
\item{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}}
}
\description{
Search for an autonomous system
}

18
man/asn_nets.Rd

@ -0,0 +1,18 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/asn-networks.R
\name{asn_nets}
\alias{asn_nets}
\title{Search for the networks announced by an autonomous system}
\usage{
asn_nets(asn, page = 1, api_key = networksdb_api_key())
}
\arguments{
\item{asn}{the autonomous system number}
\item{page}{results pagination}
\item{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}}
}
\description{
Search for the networks announced by an autonomous system
}

24
man/domains_in_network.Rd

@ -0,0 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/domains-in-network.R
\name{domains_in_network}
\alias{domains_in_network}
\title{Perform a "mass" reverse DNS lookup to find all the domain names pointing to any IPv4 or IPv6 address in the given network}
\usage{
domains_in_network(
ip_start,
ip_end,
cidr,
page = 1,
api_key = networksdb_api_key()
)
}
\arguments{
\item{ip_start, ip_end, cidr}{Either use \code{ip_start} and \code{ip_end} OR \code{cidr};}
\item{page}{results pagination}
\item{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}}
}
\description{
Perform a "mass" reverse DNS lookup to find all the domain names pointing to any IPv4 or IPv6 address in the given network
}

18
man/domains_on_ip.Rd

@ -0,0 +1,18 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/domains-on-ip.R
\name{domains_on_ip}
\alias{domains_on_ip}
\title{Perform a reverse DNS lookup to find all the domain names pointing to the given IPv4 or IPv6 address}
\usage{
domains_on_ip(ip, page = 1, api_key = networksdb_api_key())
}
\arguments{
\item{ip}{address to lookup}
\item{page}{pagination}
\item{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}}
}
\description{
Perform a reverse DNS lookup to find all the domain names pointing to the given IPv4 or IPv6 address
}

16
man/ip_geo.Rd

@ -0,0 +1,16 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ip-geo.R
\name{ip_geo}
\alias{ip_geo}
\title{Request geolocation information for a given IPv4 or IPv6 Address.}
\usage{
ip_geo(ip, api_key = networksdb_api_key())
}
\arguments{
\item{ip}{IPv4 or IPv6 address}
\item{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}}
}
\description{
Request geolocation information for a given IPv4 or IPv6 Address.
}

16
man/ip_info.Rd

@ -0,0 +1,16 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ip-info.R
\name{ip_info}
\alias{ip_info}
\title{Search for an IPv4 or IPv6 address}
\usage{
ip_info(ip, api_key = networksdb_api_key())
}
\arguments{
\item{ip}{IPv4 or IPv6 address}
\item{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}}
}
\description{
Search for an IPv4 or IPv6 address
}

16
man/ips_for_domain.Rd

@ -0,0 +1,16 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ip-for-domain.R
\name{ips_for_domain}
\alias{ips_for_domain}
\title{Perform a forward DNS lookup to find all the IPv4 and IPv6 addresses pointed to by a given domain name}
\usage{
ips_for_domain(domain, api_key = networksdb_api_key())
}
\arguments{
\item{domain}{domain to lookup}
\item{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}}
}
\description{
Perform a forward DNS lookup to find all the IPv4 and IPv6 addresses pointed to by a given domain name
}

7
man/org_networks.Rd

@ -9,8 +9,15 @@ org_networks(id, page = 1, api_key = networksdb_api_key())
\arguments{
\item{id}{id of an organisation (i.e. returned by \code{\link[=org_search]{org_search()}})}
\item{page}{results pagination; see \code{return}}
\item{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}}
}
\value{
\code{list} with \code{total} (# of results for the search), \code{page} (the current page number), and
\code{results} which is a data frame of search results. if \code{nrow()} of this data frame is >
\code{total} then there are more pages available.
}
\description{
Search for the public networks owned by an organisation.
}

Loading…
Cancel
Save