Learn R Programming

⚠️There's a newer version (1.0.2) of this package.Take me there.

ipaddress

This package provides classes for working with IP addresses, inspired by the Python ipaddress module.

Here are some of the features:

  • Fully supports both IPv4 and IPv6 address spaces
  • Efficiently stores addresses in their native format (a sequence of bits)
  • Calculations are performed in C++ for improved performance
  • Classes are compatible with the tidyverse
  • Functions for generation and analysis of IP data

Installation

You can install the released version of ipaddress from CRAN with:

install.packages("ipaddress")

Or you can install the development version from GitHub:

# install.packages("remotes")
remotes::install_github("davidchall/ipaddress")

Usage

This package provides the ip_address() and ip_network() classes, which can be used as standalone vectors or as columns within data frames and tibbles.

library(tidyverse)
library(ipaddress)

x <- tibble(
  address = ip_address(c("192.168.0.1", "2001:db8::8a2e:370:7334")),
  network = ip_network(c("192.168.100.0/22", "2001:db8::/48"))
)

x
#> # A tibble: 2 x 2
#>                   address          network
#>                 <ip_addr>       <ip_netwk>
#> 1             192.168.0.1 192.168.100.0/22
#> 2 2001:db8::8a2e:370:7334    2001:db8::/48

Input character vectors are validated as they are parsed. Invalid inputs raise a warning and are replaced with NA.

ip_address(c("255.255.255.255", "255.255.255.256"))
#> Warning: Invalid value on row 2: 255.255.255.256
#> <ip_address[2]>
#> [1] 255.255.255.255 <NA>

Functions are provided to enable common tasks:

mutate(x, ipv6 = is_ipv6(address), in_net = is_within(address, network))
#> # A tibble: 2 x 4
#>                   address          network ipv6  in_net
#>                 <ip_addr>       <ip_netwk> <lgl> <lgl> 
#> 1             192.168.0.1 192.168.100.0/22 FALSE FALSE 
#> 2 2001:db8::8a2e:370:7334    2001:db8::/48 TRUE  TRUE

Please note that the ‘ipaddress’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('ipaddress')

Monthly Downloads

388

Version

0.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

David Hall

Last Published

March 25th, 2020

Functions in ipaddress (0.2.0)

ipaddress-package

ipaddress: Tidy IP Addresses
ip_interface

Vector of IP interfaces
ipaddress-vctrs

Internal vctrs methods
ip_network

Vector of IP networks
netmask

Network mask
network_in_network

Network membership of other networks
binary

Represent address as binary
address_in_network

Network membership of addresses
max_prefix_length

Size of the address space
is_reserved

Reserved addresses
ip_address

Vector of IP addresses
hostname

Translate address to/from hostname
network_size

Network size
packed

Represent address as raw bytes
ipv6-transition

IPv6 transition mechanisms
sample

Sample random addresses
sequence

List addresses within a network
is_ipv6

Version of the address space