finding IP address of computer

2006-04-27 Thread Chris
How do I find and print to screen the IP address of the computer my
python program is working on?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-27 Thread Gregor Horvath
Chris schrieb:
> How do I find and print to screen the IP address of the computer my
> python program is working on?
> 

IP adresses are bound to network interfaces not to computers.
One Computer can have multiple network interfaces.

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-27 Thread BartlebyScrivener
One way:

>>> import socket
>>> socket.getaddrinfo(socket.gethostname(), None)[0][4][0]

It was the first google hit

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-27 Thread Chris
hehe, works a charm, cheers mate.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-27 Thread Jorge Godoy
Chris wrote:

> hehe, works a charm, cheers mate.

Beware that if you have a different entry in your hosts file you can match a
different name.

Test it:

- add "127.0.0.2yourhost.yourdomain yourhost" to /etc/hosts
- rerun the code.

You'll see "127.0.0.2" as the result.  So take that into account.

-- 
Jorge Godoy  <[EMAIL PROTECTED]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-27 Thread sturlamolden
print '127.0.0.1'

:-P

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-27 Thread Grant Edwards
On 2006-04-27, Gregor Horvath <[EMAIL PROTECTED]> wrote:
> Chris schrieb:
>> How do I find and print to screen the IP address of the computer my
>> python program is working on?
>> 
>
> IP adresses are bound to network interfaces not to computers.
> One Computer can have multiple network interfaces.

And each interface can have any number if IP addresses
(including none).

-- 
Grant Edwards   grante Yow!  I feel like a wet
  at   parking meter on Darvon!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-27 Thread Terry Reedy

"Grant Edwards" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On 2006-04-27, Gregor Horvath <[EMAIL PROTECTED]> wrote:
>> Chris schrieb:
>>> How do I find and print to screen the IP address of the computer my
>>> python program is working on?
>>>
>>
>> IP adresses are bound to network interfaces not to computers.
>> One Computer can have multiple network interfaces.
>
> And each interface can have any number if IP addresses
> (including none).

To answer the OP for typical situations: if you are accessing the internet 
via a local network, the network administrator should be able to tell you. 
In fact, for some networks, the IP address is part of the interface setup. 
If the network is run by a router, it should be able to tell you.  If you 
are sitting behind a NAT (network address translation) router and you want 
to know the external address, there are web pages that echo your externally 
visible address back to you.

Terry Jan Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-28 Thread DarkBlue
Chris wrote:

> How do I find and print to screen the IP address of the computer my
> python program is working on?

def readip():
 import re, urllib
 f = urllib.urlopen('http://checkip.dyndns.org')
 s = f.read()
 m = re.search('([\d]*\.[\d]*\.[\d]*\.[\d]*)', s)
 return m.group(0)

myip = readip()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-30 Thread Paul Watson
DarkBlue wrote:
> Chris wrote:
> 
> 
>>How do I find and print to screen the IP address of the computer my
>>python program is working on?
> 
> 
> def readip():
>  import re, urllib
>  f = urllib.urlopen('http://checkip.dyndns.org')
>  s = f.read()
>  m = re.search('([\d]*\.[\d]*\.[\d]*\.[\d]*)', s)
>  return m.group(0)
> 
> myip = readip()

IP address and other browser header information available at:

http://xhaus.com/headers
-- 
http://mail.python.org/mailman/listinfo/python-list