Machine identification

Skip Montanaro skip at pobox.com
Wed Sep 8 20:07:01 CEST 2004


    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



More information about the Python-list mailing list