How do I find my own IP address?

Chris Pressey cpressey@REDACTED
Thu Jan 22 18:48:16 CET 2004


On Thu, 22 Jan 2004 15:07:14 +0100
Joachim Durchholz <joachim.durchholz@REDACTED> wrote:

> Samuel Rivas wrote:
> > Following your discovery I've found out an (undocumented) way to get
> > the host IP within Erlang:
> > 
> > 1> {ok, S} = inet_udp:open(0, []).
> > {ok,#Port<0.4112>}
> > 2>prim_inet:ifget(S, "eth0", [addr]).
> > {ok,[{addr,{192,168,100,100}}]}
> 
> This will work on a vanilla Unix system.

Not even there (depending on your interpretation of 'vanilla Unix') -
the BSD's have not traditionally had interfaces named eth*.  They're
named after the specific devices (ed*, rl*, dc*, etc) instead.

-Chris



More information about the erlang-questions mailing list