cidr alternatives and similar packages
Based on the "Text and Numbers" category.
Alternatively, view cidr alternatives based on common mentions on social networks and blogs.
-
money
Elixir library for working with Money safer, easier, and fun... Is an interpretation of the Fowler's Money pattern in fun.prog. -
nanoid
Elixir port of NanoID, a secure and URL-friendly unique ID generator. https://hex.pm/packages/nanoid -
secure_random
Convenience library for random base64 strings modeled after my love for Ruby's SecureRandom -
chinese_translation
An elixir module to translate simplified Chinese to traditional Chinese, and vice versa, based on wikipedia data -
inet_cidr
CIDR library for Elixir that is compatible with Erlang's :inet and supports both IPv4 and IPv6 -
Ex_Cldr_Units
Unit formatting (volume, area, length, ...) functions for the Common Locale Data Repository (CLDR) -
minigen
Pure random data generation library, appropriate for realistic simulations in the Erlang ecosystem
InfluxDB - Purpose built for real-time analytics at any scale.
Do you think we are missing an alternative of cidr or a related project?
Popular Comparisons
README
CIDR
Classless Inter-Domain Routing (CIDR) utilities for Elixir
Setup
To use this library, just add :cidr
as a dependency to your mix.exs
file:
defp deps do
[
{:cidr, ">= 1.1.0"}
]
end
Usage
Passing an IP address string into CIDR.parse
returns a %CIDR{}
struct.
It contains the first and the last address of the range as Erlang IP tuples,
the amount of hosts the range covers and the network mask.
iex(1)> cidr = "1.2.3.4/24" |> CIDR.parse
%CIDR{first: {1, 2, 3, 0}, last: {1, 2, 3, 255}, hosts: 256, mask: 24}
You can query the struct for all of its fields:
iex(2)> cidr.first
{1, 2, 3, 0}
iex(3)> cidr.hosts
256
And use it to see if other IP addresses fall in the same range:
iex(4)> cidr |> CIDR.match!({1,2,3,100})
true
iex(5)> cidr |> CIDR.match!({1,2,4,1})
false
The match!/2
function also supports IP strings:
iex(6)> cidr |> CIDR.match!("1.2.3.100")
true
iex(7)> cidr |> CIDR.match!("1.2.4.1")
false
Please note that match!/2
throws an ArgumentError
when you pass in a value
that does not represent a valid IP address or when you try to match an IPv4
address with an IPv6 range and vice-versa.
We also provide match/2
, a non-throwing version that returns tagged tuples:
iex(8)> cidr |> CIDR.match("1.2.3.100")
{:ok, true}
iex(9)> cidr |> CIDR.match("1.2.4.1")
{:ok, false}
iex(10)> cidr |> CIDR.match("1.2.3.1000")
{:error, "Tuple is not a valid IP address."}
IPv4 deaggregation works as well. It returns a list of the largest possible networks for an IPv4 range in the format of $first_ip-$last_ip
:
iex(1)> CIDR.parse_range("192.168.1.0-192.168.2.0")
[
%CIDR{first: {192, 168, 1, 0}, hosts: 256, last: {192, 168, 1, 255}, mask: 24},
%CIDR{first: {192, 168, 2, 0}, hosts: 1, last: {192, 168, 2, 0}, mask: 32}
]
Contribution
See Collective Code Construction Contract (C4)
License
[Mozilla Public License 2.0](LICENSE)
*Note that all licence references and agreements mentioned in the cidr README section above
are relevant to that project's source code only.