Skip to content

Instantly share code, notes, and snippets.

@spencerwi
Last active September 9, 2015 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spencerwi/bfc551ae0fa37c0d7825 to your computer and use it in GitHub Desktop.
Save spencerwi/bfc551ae0fa37c0d7825 to your computer and use it in GitHub Desktop.
Get IPs in OCaml (using only stdlib)
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