socket.gethostbyname returns `wrong` result?

George Kinney gk_2345 at yahoo.com
Mon Jul 26 20:12:34 EDT 2004


"Frank Miles" <fpm at u.washington.edu> wrote in message
news:ce40kn$9sm$1 at gnus01.u.washington.edu...
> Unfortunately while the simple script:
>
> import socket
> print socket.gethostbyname(socket.gethostname())
>
> works on my desktop machines and server, on the laptop it gives:
> 127.0.0.1
> which, of course, doesn't provide any idea as to the state of the network.
>
> Is there any way to coerce the external IP#?  Or another way of accessing
> this number?
>
> TIA for any tips or pointers to relevant docs!

A couple of things spring to mind.

Maybe 'hostname' is defined in your hosts file as '127.0.0.1' (should be
'localhost' or sometimes 'loopback').

Are you sure that DNS is setup correctly? nslookup, ping and the like work
ok outside python (and show the correct IP)?






More information about the Python-list mailing list