Elixir - get a host by name?

How do you gethostbyname with Elixir?

The support API seems to be unsupported, and both solutions seem to revolve around,

  • Erlang inet
  • Shell plug with system ( hostname)
+4
source share
1 answer

The general philosophy in Elixir is that if a solution exists in the standard erlang libraries, there is no reason to simply reproduce this solution using the elixir cover if you are not going to provide additional features in any way.

Or, in other words, erlang libraries are native.

iex(2)> :inet.gethostbyname('www.google.com')
{:ok, {:hostent, 'www.google.com', [], :inet, 4, [{216, 58, 192, 4}]}}

Note: the single quotes above are important, you can convert the Elixir string to Erlang using String.to_charlist

iex(5)> :inet.gethostbyname(String.to_char_list("www.google.com"))
{:ok, {:hostent, 'www.google.com', [], :inet, 4, [{216, 58, 192, 4}]}}
+8
source

Source: https://habr.com/ru/post/1589300/


All Articles