Machine identification

John Fabiani jfabiani at yolo.com
Wed Sep 8 20:19:26 CEST 2004


Skip Montanaro wrote:

> 
>     Greg> How can I get the name (or ip) of the machine where my python
>     Greg> script is running?  I'd like to add it to my log entry.
> 
> % python2.3
> Python 2.3.4 (#1, Jul 19 2004, 16:02:09)
> [GCC 3.0.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import socket
>>>> socket.gethostname()
> 'manatee.mojam.com'
>>>> socket.gethostbyname(socket.gethostname())
> '199.249.165.175'
> 
> Skip
The above does not work for me. 

socket.gethostbyname(socket.gethostname())
> '127.0.0.2'

the ip address is 192.168.1.211 for the computer. And 127.0.0.2 is not
localhost.  
John



More information about the Python-list mailing list