how to obtain its ip address ?

Peter Hansen peter at
Wed Jun 23 22:36:01 CEST 2004

marco wrote:

> I'd search a lot ... but i had not found
> how can i obtain my ip address (when i'm connected to the www) ?!

You can probably search the archives for this list/newsgroup to
find more complete answers (and hints about how else to solve it),
but the short answer is "you can't".

The longer answer is that (a) machines can have multiple addresses
so you have to take that into account in the general case, (b)
there is no portable way to do it (and you didn't specify what
platform you are on), and (c) it's generally not necessary anyway,
though there are a few valid usecases... you might even have one.

On Windows you would have to parse the output of the "ipconfig"
command using os.popen or something like that.  On Linux the
command is "ifconfig", but the output is totally different.

Provide a little more info about your situation and needs and
you might get a more useful answer.


More information about the Python-list mailing list