net_address v0.1.4 IP.Range View Source

Convenience type which encapsulates the idea of a contiguous range of IP addresses.

NB

The distinction between an IP.Range and an IP.Subnet is that a Subnet must have its bounds at certain powers-of-two and multiple thereof that are governed by the subnet bit-length. A range is not constrained and is a simple "dumb list of ip addresses". Typically ranges will be proper subsets of Subnets.

Enumerable

Implements the Enumerable protocol, so the following sorts of things are possible:

iex> import IP
iex> Enum.map(~i"10.0.0.3..10.0.0.5", &IP.to_string/1)
["10.0.0.3", "10.0.0.4", "10.0.0.5"]

Link to this section Summary

Types

t()

generic ip range

ip ranges typed to either ipv4 or ipv6

Functions

converts a string to an ip range.

true if the argument is an proper ip range

Creates a new IP range, with validation.

converts a ip range to a string with delimiter ".."

Link to this section Types

generic ip range

Link to this type

t(ip_type)

View Source
t(ip_type) :: %IP.Range{first: ip_type, last: ip_type}

ip ranges typed to either ipv4 or ipv6

Link to this section Functions

Link to this function

from_string(range_str)

View Source
from_string(String.t()) :: t()

converts a string to an ip range.

The delimiter must be "..", as this is compatible with both ipv4 and ipv6 addresses

checks if the range is well-ordered.

iex> import IP
iex> IP.Range.from_string("10.0.0.3..10.0.0.5")
%IP.Range{
  first: {10, 0, 0, 3},
  last: {10, 0, 0, 5}
}
Link to this macro

is_range(range)

View Source (macro)
is_range(any()) :: Macro.t()

true if the argument is an proper ip range

checks if the range is well-ordered.

usable in guards.

iex> import IP
iex> IP.Range.is_range(~i"10.0.0.1..10.0.0.3")
true
iex> IP.Range.is_range(:foo)
false
iex> IP.Range.is_range(%IP.Range{first: ~i"10.0.0.3", last: ~i"10.0.0.1"})
false
Link to this function

new(first, last)

View Source
new(IP.addr(), IP.addr()) :: t()

Creates a new IP range, with validation.

If your provide an out-of-order range, it will raise ArgumentError.

iex> IP.Range.new({10, 0, 0, 1}, {10, 0, 0, 5})
%IP.Range{
  first: {10, 0, 0, 1},
  last: {10, 0, 0, 5}
}
Link to this function

to_string(range)

View Source
to_string(t()) :: String.t()

converts a ip range to a string with delimiter ".."

checks if the range is well-ordered.

iex> IP.Range.to_string(%IP.Range{first: {10, 0, 0, 3},last: {10, 0, 0, 5}})
"10.0.0.3..10.0.0.5"