Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > socket.gethostbyname returns `wrong` result?

Reply
Thread Tools

socket.gethostbyname returns `wrong` result?

 
 
Frank Miles
Guest
Posts: n/a
 
      07-26-2004
Hi everyone...

I'm trying to use the IP address as a way of detecting the current state
of my laptop. [Using laptop-net, it senses what network it's connected
to, and configures various parameters including IP address. This seems
to work properly, as reflected in the `ifconfig` output.]

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!

-frank
--
 
Reply With Quote
 
 
 
 
Irmen de Jong
Guest
Posts: n/a
 
      07-26-2004
Frank Miles wrote:

> 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.


Do you have, by any chance, an entry in your hosts file like this:

127.0.0.1 <real hostname>

If so, remove that line! The hosts file should only contain :

127.0.0.1 localhost

for the 127.0.0.1 address.

-Irmen
 
Reply With Quote
 
 
 
 
George Kinney
Guest
Posts: n/a
 
      07-27-2004

"Frank Miles" <(E-Mail Removed)> wrote in message
news:ce40kn$9sm$(E-Mail Removed)...
> 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)?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorted Returns List and Reversed Returns Iterator ++imanshu Python 7 08-23-2008 04:25 AM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
createImage sometime returns null and sometime returns non-null. vizlab Java 3 10-17-2007 11:21 AM
block returns and hash element returns Trans Ruby 2 11-06-2005 12:15 PM
Device search returns devices with zero length strings =?Utf-8?B?U3RlcGhlbiBJbmtwZW4=?= Wireless Networking 2 07-15-2005 12:26 AM



Advertisments