net_address v0.2.2 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
Functions
Finds an ip range in a string, returning an ok or error tuple on failure.
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
ip ranges typed to either ipv4 or ipv6
Link to this section Functions
Finds an ip range in a string, returning an ok or error tuple on failure.
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}
}
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
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}
}
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"