boB Rudis
4 years ago
17 changed files with 321 additions and 7 deletions
@ -0,0 +1,2 @@ |
|||
YEAR: 2020 |
|||
COPYRIGHT HOLDER: Bob Rudis |
@ -0,0 +1,21 @@ |
|||
# MIT License |
|||
|
|||
Copyright (c) 2020 Bob Rudis |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
@ -1,4 +1,8 @@ |
|||
# Generated by roxygen2: do not edit by hand |
|||
|
|||
export(networksdb_api_key) |
|||
export(org_info) |
|||
export(org_networks) |
|||
export(org_search) |
|||
import(httr) |
|||
importFrom(jsonlite,fromJSON) |
|||
|
@ -0,0 +1,4 @@ |
|||
httr::user_agent(sprintf( |
|||
"networksdb R package %s; (<https://gitlab.com/hrbrmstr/networksdb>)", |
|||
utils::packageVersion("networksdb") |
|||
)) -> .NETWORKS_DB_UA |
@ -1,9 +1,15 @@ |
|||
#' ... |
|||
#' |
|||
#' Query Organization, IP, DNS, and Network Info From NetworksDB |
|||
#' |
|||
#' NetworksDB <https://networksdb.io> contains information about the public IPv4 and |
|||
#' IPv6 addresses, networks and domains owned by companies and organisations across the world |
|||
#' along with city-level IP geolocation data and autonomous system information. Tools are provided |
|||
#' to query the NetworksDB API. |
|||
#' |
|||
#' @md |
|||
#' @name networksdb |
|||
#' @keywords internal |
|||
#' @author Bob Rudis (bob@@rud.is) |
|||
#' @import httr |
|||
#' @importFrom jsonlite fromJSON |
|||
#' @references <https://networksdb.io/api/docs> |
|||
"_PACKAGE" |
|||
|
@ -0,0 +1,32 @@ |
|||
#' Get or set NetworksDB Personal Access Token |
|||
#' |
|||
#' @param force force setting a new NetworksDB API Key |
|||
#' @return atomic character vector containing the NetworksDB API key |
|||
#' @references <https://networksdb.io/api/order/free> |
|||
#' @export |
|||
networksdb_api_key <- function(force = FALSE) { |
|||
|
|||
pat <- Sys.getenv('NETWORKS_DB_API_KEY') |
|||
if (!identical(pat, "") && !force) { |
|||
return(pat) |
|||
} |
|||
|
|||
if (!interactive()) { |
|||
stop("Please set env var NETWORKS_DB_API_KEY to your NetworksDB API Key", |
|||
call. = FALSE) |
|||
} |
|||
|
|||
message("Couldn't find env var NETWORKS_DB_API_KEY See ?networksdb_api_key for more details.") |
|||
message("Please enter your NetworksDB API key and press enter:") |
|||
pat <- readline(": ") |
|||
|
|||
if (identical(pat, "")) { |
|||
stop("NetworksDB API key entry failed", call. = FALSE) |
|||
} |
|||
|
|||
message("Updating NETWORKS_DB_API_KEY env var") |
|||
Sys.setenv(NETWORKS_DB_API_KEY = pat) |
|||
|
|||
pat |
|||
|
|||
} |
@ -0,0 +1,25 @@ |
|||
#' Retreive information about an organisation. |
|||
#' |
|||
#' @param id id of an organisation (i.e. returned by [org_search()]) |
|||
#' @param api_key see [networksdb_api_key()] |
|||
#' @export |
|||
org_info <- function(id, api_key = networksdb_api_key()) { |
|||
|
|||
httr::GET( |
|||
url = "https://networksdb.io/api/org-info", |
|||
query = list( |
|||
id = id[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 |
|||
|
|||
} |
@ -0,0 +1,26 @@ |
|||
#' Search for the public networks owned by an organisation. |
|||
#' |
|||
#' @param id id of an organisation (i.e. returned by [org_search()]) |
|||
#' @param api_key see [networksdb_api_key()] |
|||
#' @export |
|||
org_networks <- function(id, page = 1, api_key = networksdb_api_key()) { # ipv6 |
|||
|
|||
httr::GET( |
|||
url = "https://networksdb.io/api/org-networks", |
|||
query = list( |
|||
id = id[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 |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
#' Search for organisations matching a search term. |
|||
#' |
|||
#' @param query search terms |
|||
#' @param country if not `NULL` (the default) a single ISO2C country code |
|||
#' @param page page number (the query result set may have multiple pages; the current page number |
|||
#' of the result is a slot in the return value list.) |
|||
#' @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_search <- function(query, country = NULL, page = 1, api_key = networksdb_api_key()) { |
|||
|
|||
httr::GET( |
|||
url = "https://networksdb.io/api/org-search", |
|||
query = list( |
|||
search = query[1], |
|||
country = country[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 |
|||
|
|||
} |
@ -0,0 +1,73 @@ |
|||
|
|||
[![Project Status: Active – The project has reached a stable, usable |
|||
state and is being actively |
|||
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) |
|||
[![Signed |
|||
by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) |
|||
![Signed commit |
|||
%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg) |
|||
[![Linux build |
|||
Status](https://travis-ci.org/hrbrmstr/networksdb.svg?branch=master)](https://travis-ci.org/hrbrmstr/networksdb) |
|||
![Minimal R |
|||
Version](https://img.shields.io/badge/R%3E%3D-3.2.0-blue.svg) |
|||
![License](https://img.shields.io/badge/License-MIT-blue.svg) |
|||
|
|||
# networksdb |
|||
|
|||
Query Organization, IP, DNS, and Network Info From NetworksDB |
|||
|
|||
## Description |
|||
|
|||
NetworksDB <https://networksdb.io> contains information about the public |
|||
IPv4 and IPv6 addresses, networks and domains owned by companies and |
|||
organisations across the world along with city-level IP geolocation data |
|||
and autonomous system information. Tools are provided to query the |
|||
NetworksDB API. |
|||
|
|||
## What’s Inside The Tin |
|||
|
|||
The following functions are implemented: |
|||
|
|||
- `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 |
|||
organisation. |
|||
- `org_search`: Search for organisations matching a search term. |
|||
|
|||
## Installation |
|||
|
|||
``` r |
|||
remotes::install_git("https://git.rud.is/hrbrmstr/networksdb.git") |
|||
# or |
|||
remotes::install_git("https://git.sr.ht/~hrbrmstr/networksdb") |
|||
# or |
|||
remotes::install_gitlab("hrbrmstr/networksdb") |
|||
# or |
|||
remotes::install_github("hrbrmstr/networksdb") |
|||
``` |
|||
|
|||
NOTE: To use the ‘remotes’ install options you will need to have the |
|||
[{remotes} package](https://github.com/r-lib/remotes) installed. |
|||
|
|||
## Usage |
|||
|
|||
``` r |
|||
library(networksdb) |
|||
|
|||
# current version |
|||
packageVersion("networksdb") |
|||
## [1] '0.1.0' |
|||
``` |
|||
|
|||
## 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 | |
|||
|
|||
## Code of Conduct |
|||
|
|||
Please note that this project is released with a Contributor Code of |
|||
Conduct. By participating in this project you agree to abide by its |
|||
terms. |
@ -0,0 +1,20 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/networksdb-pat.R |
|||
\name{networksdb_api_key} |
|||
\alias{networksdb_api_key} |
|||
\title{Get or set NetworksDB Personal Access Token} |
|||
\usage{ |
|||
networksdb_api_key(force = FALSE) |
|||
} |
|||
\arguments{ |
|||
\item{force}{force setting a new NetworksDB API Key} |
|||
} |
|||
\value{ |
|||
atomic character vector containing the NetworksDB API key |
|||
} |
|||
\description{ |
|||
Get or set NetworksDB Personal Access Token |
|||
} |
|||
\references{ |
|||
\url{https://networksdb.io/api/order/free} |
|||
} |
@ -0,0 +1,16 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/org-info.R |
|||
\name{org_info} |
|||
\alias{org_info} |
|||
\title{Retreive information about an organisation.} |
|||
\usage{ |
|||
org_info(id, api_key = networksdb_api_key()) |
|||
} |
|||
\arguments{ |
|||
\item{id}{id of an organisation (i.e. returned by \code{\link[=org_search]{org_search()}})} |
|||
|
|||
\item{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}} |
|||
} |
|||
\description{ |
|||
Retreive information about an organisation. |
|||
} |
@ -0,0 +1,16 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/org-networks.R |
|||
\name{org_networks} |
|||
\alias{org_networks} |
|||
\title{Search for the public networks owned by an organisation.} |
|||
\usage{ |
|||
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{api_key}{see \code{\link[=networksdb_api_key]{networksdb_api_key()}}} |
|||
} |
|||
\description{ |
|||
Search for the public networks owned by an organisation. |
|||
} |
@ -0,0 +1,26 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/org-search.R |
|||
\name{org_search} |
|||
\alias{org_search} |
|||
\title{Search for organisations matching a search term.} |
|||
\usage{ |
|||
org_search(query, country = NULL, page = 1, api_key = networksdb_api_key()) |
|||
} |
|||
\arguments{ |
|||
\item{query}{search terms} |
|||
|
|||
\item{country}{if not \code{NULL} (the default) a single ISO2C country code} |
|||
|
|||
\item{page}{page number (the query result set may have multiple pages; the current page number |
|||
of the result is a slot in the return value list.)} |
|||
|
|||
\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 organisations matching a search term. |
|||
} |
Loading…
Reference in new issue