Cider v0.2.0 Cider View Source

Parsing and matching of CIDRs with ips.

Link to this section Summary

Types

A tuple with each octet of the ip

t()

A cidr made out of {ip, subnet_mask}

Functions

Checks whether a given ip falls within a cidr range

Returns the raw numeric IP

Parses a CIDR in string representation

Creates a CIDR based on an ip and bit_mask

Parses a CIDR in list representation. The first 4 items are the octets of the ip. The last item is the bit mask

Convert a tuple or numeric IP to string

Link to this section Types

A tuple with each octet of the ip.

A cidr made out of {ip, subnet_mask}.

Link to this section Functions

Link to this function

contains?(ip, arg) View Source
contains?(ip() | raw_ip(), t()) :: boolean()

Checks whether a given ip falls within a cidr range.

Example

iex> Cider.contains?({192, 168, 0, 1}, Cider.parse({192, 168, 0, 0}, 24))
true
iex> Cider.contains?(3232235520, Cider.parse({192, 168, 0, 0}, 24))
true
iex> Cider.contains?({192, 168, 254, 1}, Cider.parse({192, 168, 0, 0}, 24))
false

Returns the raw numeric IP.

Examples

iex> Cider.ip!("192.168.1.1")
3_232_235_777
iex> Cider.ip!({192, 168, 1, 1})
3_232_235_777

Parses a CIDR in string representation.

Examples

iex> Cider.parse "192.168.0.0/24"
{3232235520, 4294967040}
Link to this function

parse(ip, bit_mask) View Source
parse(ip(), integer() | nil) :: t()

Creates a CIDR based on an ip and bit_mask.

The ip is represented by an octet tuple.

Examples

iex> Cider.parse {192, 168, 0, 0}, 24
{3232235520, 4294967040}
iex> Cider.parse {0, 0, 0, 0, 0, 65535, 49320, 10754}, 128
{281473913989634, 340282366920938463463374607431768211455}
Link to this function

parse(a, b, c, d, bit_mask \\ nil) View Source
parse(integer(), integer(), integer(), integer(), integer() | nil) :: t()

Parses a CIDR in list representation. The first 4 items are the octets of the ip. The last item is the bit mask.

Examples

iex> Cider.parse 192, 168, 0, 0, 24
{3232235520, 4294967040}
Link to this function

to_string(ip) View Source
to_string(tuple() | integer()) :: String.t()

Convert a tuple or numeric IP to string.

Examples

iex> Cider.to_string({192, 168, 1, 1})
"192.168.1.1"
iex> Cider.to_string(3_232_235_777)
"192.168.1.1"
iex> Cider.to_string({0, 0, 0, 0, 0, 65535, 49320, 10754})
"0:0:0:0:0:FFFF:C0A8:2A02"
iex> Cider.to_string(281_473_913_989_634)
"0:0:0:0:0:FFFF:C0A8:2A02"