[erlang-questions] how to get the factual ip address?

Steve Vinoski vinoski@REDACTED
Sun Oct 26 02:09:15 CEST 2008

On 10/25/08, litao cheng <litaocheng@REDACTED> wrote:
> hi, everyone.
> I want to get the factual  ip address of my host. when I use the
> inet:gethostname earn my host name. and then use the inet:gethostbyname/1 or
> inet:getaddrs/2 to get the ip address.  the results is :
>  I can use the ifconfig to see the ip address of eth0 is, I
> want to get this value. how can I do it?
> btw, If it relate to the inetrc config of kernel app?
> (my computer os is ubuntu 8.04, OTP R12B4)

There's the following undocumented function:

1> inet:ifget("eth0", [addr]).

On Ubuntu "eth0" should work for you, but if you want to know what
interfaces you have:

2> inet:getiflist().

Also note you can change the IP address tuple to a string like this:

3> inet_parse:ntoa({192,168,1,101}).

and back again:

4> inet_parse:address("").


More information about the erlang-questions mailing list