Created
October 18, 2017 01:44
-
-
Save wesleyit/b01c5718de61f015e7d0eb54554bae71 to your computer and use it in GitHub Desktop.
Get all IPs addresses using Elixir
This file contains hidden or 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 IPCluster do | |
def get_inet(), do: elem(:inet.getif(), 1) | |
def get_ip_list([]), do: [] | |
def get_ip_list([h|t]) do | |
{ip, _bcast, mask} = h | |
[[Tuple.to_list(ip), Tuple.to_list(mask)] | get_ip_list(t)] | |
end | |
def ip_list([]), do: [] | |
def ip_list([h|t]) do | |
[Enum.at(h,0) | ip_list(t)] | |
end | |
end | |
IPCluster.get_inet() |> | |
IPCluster.get_ip_list() |> | |
IPCluster.ip_list() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a = 192
b = 168
c = 0..255
d = 1..254
ips = for x <- c, y <- d, do: [a, b, x, y]
Enum.slice(ips, (length(ips) - 10), 10)