logo       

Re: How do I find my own IP address?: msg#00263

lang.erlang.general

Subject: Re: How do I find my own IP address?

Samuel Rivas wrote:

If the name of possible interfaces bothers you, there is another
(and undocumented too) function that will return an interesting list:

1> inet:getiflist(S).
{ok,["lo","eth0"]}

The real problem is those functions are not in the public API, so they
could be changed in future releases.

Finally I've no idea of how Windows names its interfaces, and no
chance to test getiflist in a Windows host ...

Results from a Windows machine:

Erlang (BEAM) emulator version 5.3 [threads:0]

Eshell V5.3 (abort with ^G)
1> {ok, S} = inet_udp:open(0, []).
{ok,#Port<0.30>}
2> inet:getiflist(S).
{ok,["50.240.861.291","100.0.0.721"]}
3>

The IP addresses on this machine are 127.0.0.1 (of course) and 192.168.42.50...

Regards
Björn




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise