How do I find my own IP address?

Luke Gorrie <>
Wed Jan 21 17:01:15 CET 2004


Joe Armstrong <> writes:

> I need to know my own IP address

For what purpose? There's no simple answer because you don't
necessarily just have one IP address, and there are different ways to
find the right IP address for different purposes.

If you want to tell someone else your IP address and you already know
theirs, it's probably best to just connect to them and let them see
what address you used. If they have a socket connected to you then
they can get your address from inet:peername/2.

Alternatively you could ask the OS "what address should I use to talk
with <other ip>?" - I'm not sure if you can do that portably, but on a
modern Linux box you can do a manual lookup like:

  $ ip route get 192.168.128.1
  192.168.128.1 dev eth0  src 192.168.128.44 
      cache  mtu 1500 advmss 1460

which says I can use source address 192.168.128.44 to talk to
192.168.128.1.

Depending on what you're doing you might also want to be careful about
NAT. Maybe the address your computer thinks you have is not the same
one other people will see.

Cheers,
Luke (confident that Per will correct all my errors :-)




More information about the erlang-questions mailing list