Last active
September 9, 2015 02:11
-
-
Save spencerwi/bfc551ae0fa37c0d7825 to your computer and use it in GitHub Desktop.
Get IPs in OCaml (using only stdlib)
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
module StringSet = Set.Make(String) | |
let addr_to_string = function | |
| Unix.ADDR_UNIX s -> s | |
| Unix.ADDR_INET (iaddr, _) -> Unix.string_of_inet_addr iaddr | |
let get_local_ips () = | |
Unix.getaddrinfo "localhost" "" [] | |
|> List.map (fun x -> x.Unix.ai_addr) | |
let () = | |
get_local_ips() | |
|> List.map addr_to_string | |
|> StringSet.of_list | |
|> StringSet.iter print_endline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment