473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

socket.gethostbyname returns `wrong` result?

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
--
Jul 18 '05 #1
2 5898
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
Jul 18 '05 #2

"Frank Miles" <fp*@u.washington.edu> wrote in message
news:ce**********@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)?

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eric Brunel | last post by:
Hi all, I just compiled Python 2.3.2 on Linux Mandrake 8.0, upgrading from Python 2.1. I have one problem that I can't figure out: when I wanted to get "the" IP address of the current host with...
1
by: Fortepianissimo | last post by:
I've tried using socket.setdefaulttimeout(timeout) to set the default timeout to 'timeout' for all sockets. The part that's not clear to me, is that if this will affect...
0
by: Jacob Lee | last post by:
I'm getting a rather bizarre error while using the socket module. If I start out disconnected from the net and then connect while the program or interpreter session is open, I do not always gain...
10
by: Sheila King | last post by:
I'm doing DNS lookups on common spam blacklists (such as SpamCop..and others) in an email filtering script. Sometimes, because the DNS server that is resolving the looksup can go down, it is...
10
by: balzano_1 | last post by:
Hi, im trying to send text from one pc to anther using C socket programming, i used send() to send the text, the text i used to send is a result of a function, the problem is the other side...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
2
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then...
2
by: flamesrock | last post by:
Hi, Basically, I'm trying to send a multipart form to a server using some code from aspn.. here it is: MultipartPostHandler: http://pastie.caboo.se/29833 import MultipartPostHandler, urllib2,...
8
by: half.italian | last post by:
Hi all, I'm having trouble with the socket module resolving a hostname. It seems like this is a system level problem, but I'm not even sure where to start. I can ping the smtp server by name...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.