469,936 Members | 2,402 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

how to obtain its ip address ?

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
Jul 18 '05 #1
6 1660
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.

-Peter
Jul 18 '05 #2
marco <ma******@online.fr> 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) ?!
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/Webwa.../Funcs.py.html

This appears to be a bit more systematic in getting a good local IP
address.
Good luck to you!
Jul 18 '05 #3
On 2004-06-23, marco <ma******@online.fr> 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) ?!

Probably it will depend somewhat on your operating system.
This works for me ...
import socket
socket.gethostbyname('localhost') '127.0.0.1' hostname = socket.gethostname()
hostname 'homer' socket.gethostbyname(hostname)

'172.16.0.5'

Jul 18 '05 #4
In article <H-********************@powergate.ca>,
Peter Hansen <pe***@engcorp.com> wrote:
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

Jul 18 '05 #5
Cameron Laird wrote:
In article <H-********************@powergate.ca>,
Peter Hansen <pe***@engcorp.com> wrote:
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

.
Even more details appear at <URL:
http://wiki.tcl.tk/MyOwnIPAddress >.


Thanks Cameron. That's a pretty good page (especially if you like
TCL), and it doesn't even get into issues relating to SNAT/DNAT,
routers, firewalls, and the like, which many of us are behind these
days...
Jul 18 '05 #6
marco <ma******@online.fr> wrote in message news:<40***********************@news.free.fr>...
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
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jeronimo Bertran | last post: by
1 post views Thread by HB2 | last post: by
7 posts views Thread by Brian Cryer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.