nobody
How to get the server ip address?
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
Most Liked
Linuus
Try to call the erlang function :inet.getif()
dom
Something like this should do the trick
{:ok, ifs} = :inet.getif()
ips = Enum.map(ifs, fn {ip, _broadaddr, _mask} -> ip end)
I think getif is not documented, so technically it could disappear eventually. getifaddrs may be a more future-proof option. Note in practice this will return multiple IPs since you’ll have at least a loopback and an external IP.
You’ll find more options if you google something like “erlang get ip”, whatever works in Erlang will also work in Elixir.
joe
If anyone else is looking for it’s own IP address and finds this thread… In my nerves project I use :inet.getif/0 and loop through the result until I find one that fits my pattern (e.g. one that starts with 192.168).







