How do you gethostbyname with Elixir?
There doesn't seem to be a supported API and the two solutions seem to revolve around,
hostname
)The general philosophy in Elixir is that if a solution exists in standard erlang libraries, there is no reason to simply reproduce that solution with a elixir wrapper unless you are going to provide added functionality in some 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 an Elixir string to an Erlang one by 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}]}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With