liaison v0.1.0 Liaison.IP View Source
Allow the conversion of common IP formats to and from
- string: "1.2.3.4"
- component: {1, 2, 3, 4}
- integer: 16909060
Input formats can be equal to output formats
Example
iex> Liaison.IP.as_string("1.2.3.4")
"1.2.3.4"
Link to this section Summary
Functions
Converts any valid address into a tuple {a, b, c, d}
Converts any valid address into an integer
Converts any valid address into a string a.b.c.d
Returns the localhost ip address in component form.
If there is more than one ip address for the machine, the nth
can be returned. Else nil
Returns true if the given address is valid.
This checks if the format is correct, not if the address is
functionally valid or accessible
Creates a range of integer ip addresses between the given addresses. Inclusivity: [from, to]
Link to this section Types
Link to this section Functions
Converts any valid address into a tuple {a, b, c, d}
Example
iex> Liaison.IP.as_components("1.2.3.4")
{1, 2, 3, 4}
iex> Liaison.IP.as_components(16909060)
{1, 2, 3, 4}
iex> Liaison.IP.as_components({1, 2, 3, 4})
{1, 2, 3, 4}
Converts any valid address into an integer
Example
iex> Liaison.IP.as_integer("1.2.3.4")
16909060
iex> Liaison.IP.as_integer(16909060)
16909060
iex> Liaison.IP.as_integer({1, 2, 3, 4})
16909060
Converts any valid address into a string a.b.c.d
Example
iex> Liaison.IP.as_string("1.2.3.4")
"1.2.3.4"
iex> Liaison.IP.as_string(16909060)
"1.2.3.4"
iex> Liaison.IP.as_string({1, 2, 3, 4})
"1.2.3.4"
Returns the localhost ip address in component form.
If there is more than one ip address for the machine, the nth
can be returned. Else nil
Returns true if the given address is valid.
This checks if the format is correct, not if the address is
functionally valid or accessible
Example
iex> Liaison.IP.is_valid?("1.2.3.4")
true
iex> Liaison.IP.is_valid?({1, 2, 3, 400})
false
Creates a range of integer ip addresses between the given addresses. Inclusivity: [from, to]
Example
iex> Liaison.IP.to_ip_range("1.2.3.4", "1.2.3.6", :string)
["1.2.3.4", "1.2.3.5", "1.2.3.6"]
iex> Liaison.IP.to_ip_range("1.2.3.6", "1.2.3.4")
{:error, "ip1 > ip2"}