Created
July 28, 2015 14:26
-
-
Save ubernil/8da37bcd69bc022ebd05 to your computer and use it in GitHub Desktop.
CidrCalc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule CidrCalc do | |
def addresses_for(ip) do | |
{:ok, range_start, range_end}= String.to_char_list(ip) |> :orber_acl.range(:inet) | |
[net_a, net_b, net_c, net_d] = Enum.zip(convert(range_start), convert(range_end)) | |
|> Enum.map(fn {s, e} -> s..e end) | |
for a <- net_a, b <- net_b, c <- net_c, d <- net_d, do: {a, b, c, d} | |
end | |
defp convert(charlist_ip) do | |
charlist_ip | |
|> List.to_string | |
|> String.split(".") | |
|> Enum.map(&String.to_integer(&1)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment