How to get IP address

Ulrich Petri ulope at
Wed Mar 5 17:25:32 CET 2003

"Wayne Pierce" <wayne at> schrieb im Newsbeitrag
news:2a897f11.0303040243.48067d01 at
> Nagy László Zsolt <nagylzs at> wrote in message
news:<mailman.1046693203.18366.python-list at>...

> > When you call gethostbyaddr('hostname1'), you will get addresses for
> > 'hostname1' only:  ['','']
> Exactly, you are specifying that you only want to see the data for the
> specified hostname.  If you do not put a specific hostname and use
> socket.gethostname() it should give you the info for everything.
> > You can't use gethostbyaddr() if you don't know IP address neither a DNS
> > name. ;-)
> Yes, you can.  gethostbyaddr() can be pointed to the local system in a
> couple of different ways without an IP or DNS name, you could use
> 'localhost' and gethostname().

using localhost is propably not what he wants:

Python 2.1.3 (#1, Feb 24 2003, 20:48:47)
[GCC 2.95.3 20010315 (release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostbyaddr('localhost')
('localhost', [], [''])

and yes this machine has (several) other Hostnames and ips

Ciao Ulrich

More information about the Python-list mailing list