How do I find my own IP address?

Bengt Kleberg Bengt.Kleberg@REDACTED
Wed Jan 21 16:45:31 CET 2004


Joe Armstrong wrote:
> I need to know my own IP address
> 
> I can find my hostname
> 
> 1> inet:gethostname().
> {ok,"enfield"}
> 
> And do this
> 
> 2> inet:gethostbyname("enfield").
>  
> {ok,{hostent,"localhost.localdomain",
>              ["localhost","enfield"],
>              inet,
>              4,
>              [{127,0,0,1}]}}
> 
> But 127.0.0.1 is not my IP address
> 

i tried the functions and got the expected results:

inet:gethostname().
{ok,"wsb017"}
2> inet:gethostbyname(
"wsb017"
).
{ok,{hostent,"wsb017",["loghost"],inet,4,[{134,138,232,116}]}}

before using undocumented functions i would suggest a close look at the 
configuration of your computer. the #hostent{} claims your canonical 
name is "localhost.localdomain". this does not sound correct.
what does your /etc/hosts say?


bengt



More information about the erlang-questions mailing list