Giter Site home page Giter Site logo

pgcidr's Introduction

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Signed by Signed commit % Linux build Status
Minimal R Version License

pgcidr

Perform IP Address in CIDR Lookups with PostgreSQL and ip4r

Description

PostgreSQL has built-in support for IP address and CIDR types but the ip4r https://github.com/RhodiumToad/ip4r extension is much faster. Tools are provided to create CIDR lookup and IP address source tables and perform IP address in CIDR queries. Documentation on how to setup macOS with PostgreSQL and ip4r is also provided.

What’s Inside The Tin

The following functions are implemented:

  • create_cidr_lookup_table: Creates a CIDR lookup table
  • create_ip_source_table: Creates a IP address table
  • find_ips_in_cidrs: Finds IPs in CIDR blocks
  • macos_postgresql_setup_with_ip4r: Setting up macOS PostgreSQL 12 with ip4r extension

Installation

install.packages("pgcidr", repos = c("https://cinc.rud.is", "https://cloud.r-project.org/"))
# or
remotes::install_git("https://git.rud.is/hrbrmstr/pgcidr.git")
# or
remotes::install_git("https://git.sr.ht/~hrbrmstr/pgcidr")
# or
remotes::install_gitlab("hrbrmstr/pgcidr")
# or
remotes::install_bitbucket("hrbrmstr/pgcidr")
# or
remotes::install_github("hrbrmstr/pgcidr")

NOTE: To use the ‘remotes’ install options you will need to have the {remotes} package installed.

Usage

library(pgcidr)

# current version
packageVersion("pgcidr")
## [1] '0.1.0'
DBI::dbConnect(
  odbc::odbc(),
  driver = "/usr/local/lib/psqlodbca.so",
  Database = "working",
  Host = "localhost"
) -> con

create_cidr_lookup_table(
  pgcon = con,
  tbl_name = "amazon_cidrs",
  drop = TRUE,
  xdf = system.file("extdat", "amzn-cidrs.csv", package = "pgcidr"),
)

create_ip_source_table(
  pgcon = con,
  tbl_name = "weblog",
  drop = TRUE,
  xdf = system.file("extdat", "weblog.csv", package = "pgcidr")
)

find_ips_in_cidrs(
  con, "weblog", "amazon_cidrs"
)

## # A tibble: 83 x 3
##    ip             entity        cidr         
##    <chr>          <chr>         <chr>        
##  1 54.235.230.238 us-east-1     54.234.0.0/15
##  2 54.227.107.78  us-east-1     54.226.0.0/15
##  3 96.127.69.213  us-gov-west-1 96.127.0.0/17
##  4 3.82.223.254   us-east-1     3.80.0.0/12  
##  5 3.83.153.45    us-east-1     3.80.0.0/12  
##  6 54.160.105.136 us-east-1     54.160.0.0/13
##  7 54.225.41.245  us-east-1     54.224.0.0/15
##  8 3.87.18.119    us-east-1     3.80.0.0/12  
##  9 54.91.31.71    us-east-1     54.88.0.0/14 
## 10 54.90.66.13    us-east-1     54.88.0.0/14 
## # … with 73 more rows

pgcidr Metrics

Lang # Files (%) LoC (%) Blank lines (%) # Lines (%)
R 7 0.88 75 0.72 37 0.65 177 0.8
Rmd 1 0.12 29 0.28 20 0.35 44 0.2

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.

pgcidr's People

Contributors

hrbrmstr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jimsforks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.