Created
January 30, 2012 23:56
-
-
Save marccampbell/1707641 to your computer and use it in GitHub Desktop.
Get Private IP Address
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
{ok, Interfaces} = inet:getifaddrs(), | |
Addresses = lists:map(fun({_, Props}) -> proplists:get_all_values(addr, Props) end, Interfaces), | |
Private_Addresses = lists:filter(fun({F,_,_,_}) -> lists:member(F, [10, 172, 192]); (_) -> false end, lists:flatten(Addresses)), | |
io:format("Private Addresses = ~p\n", [Private_Addresses]), | |
case Private_Addresses of | |
[] -> io:format("Unable to start monitor listener, no private address was found.\n", []), | |
undefined; | |
_ -> {A, B, C, D} = lists:nth(1, Private_Addresses), | |
IP_Address = lists:flatten(io_lib:format("~.10B.~.10B.~.10B.~.10B", [A, B, C, D])), | |
io:format("Starting listener on ~s\n", [IP_Address]), | |
IP_Address | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment