how to obtain its ip address ?

M

marco

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

thanks a lot for any tips
marco
 
P

Peter Hansen

marco said:
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.

-Peter
 
D

Daniel Yoo

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


Hi Marco,


Here's a quicky way to do it:

###
import socket

def getSelfIp():
"""Returns the IP address of the local host."""
return socket.gethostbyname(socket.gethostname())
###


This might not work perfectly. If you want something more
comprehensive, you may want to use something like the localIP()
function in Webware:

http://webware.sourceforge.net/Webware-0.8b2/MiscUtils/Docs/Source/Files/Funcs.py.html

This appears to be a bit more systematic in getting a good local IP
address.


Good luck to you!
 
L

Lee Harr

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


Probably it will depend somewhat on your operating system.
This works for me ...
'172.16.0.5'
 
M

Michele Simionato

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

thanks a lot for any tips
marco

In may case on linux this worked:

$ wget -q "http://ipid.shat.net/iponly" -O - |sed -n 3p

This gives your address as seen from outside, which is probably
what you want, whereas other solutions I tried were giving me
my local address on the LAN.

Michele Simionato
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top