Cider v0.2.0 Cider View Source
Parsing and matching of CIDRs with ips.
Link to this section Summary
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.
raw_ip()
View Source
raw_ip() :: integer()
raw_ip() :: integer()
A cidr made out of {ip
, subnet_mask
}.
Link to this section Functions
contains?(ip, arg) View Source
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
ip!(ip) View Source
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
parse(cidr) View Source
Parses a CIDR in string representation.
Examples
iex> Cider.parse "192.168.0.0/24"
{3232235520, 4294967040}
parse(ip, bit_mask) View Source
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}
parse(a, b, c, d, bit_mask \\ nil) View Source
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}
to_string(ip) View Source
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"