2

In my local network exists pcs, where have a hostname as example "testhost". How can I from given hostname get a IP-address ?

I tried:

net_adm:dns_hostname("testhost.fritz.box").

Result:

{ok,"testhost.fritz.box"}

I need a function which give me IP-Address from hostname.

Thx

david
  • 83
  • 1
  • 13

1 Answers1

5

According to http://erlang.org/doc/man/inet.html#getaddr-2 it seems you should be able to use getaddr like:

inet:getaddr("testhost.fritz.box", inet)
Kenny Evitt
  • 9,291
  • 5
  • 65
  • 93
Max Senft
  • 610
  • 4
  • 13
  • 1
    In Elixir code, you can call this like `"testhost.fritz.box" |> String.to_charlist() |> :inet.getaddr(:inet)`. (The regular Elixir string literals seem to result in an `einval` error. – Kenny Evitt Oct 04 '21 at 17:08