Checking if the computer is online

Mickel Grönroos mickel at csc.fi
Tue Sep 23 03:05:04 EDT 2003


On Thu, 18 Sep 2003, Thomas Bellman wrote:

> Mickel Grönroos <mickel at csc.fi> wrote:
>
> > Hi all,
>
> > I have a silly question. Is there are simple way to check if the computer
> > is connected to the Internet? It seems this should be a pretty
> > straight-forward thing to do, but as I am totally unfamiliar with sockets
> > and such, I ask for your help before getting my hands dirty.
>
> First of all you need to define what "being online" means...
[...]
> Or perhaps you should tell us *why* you believe you need to check
> if the computer is connected to the Internet or not.  Then we can
> go directly to telling you that it is a bad idea, and suggest what
> you should do instead. <0.5 wink>

OK, here's what I want to do:

When the Tkinter application I am writing starts up, it checks if certain
files on the web exists and if so, it downloads them to a local directory
replacing possible earlier copies of these files. So, what I mean by
checking if the computer is online is that I want to check if I can access
these certain remote files with urllib.urlretrieve(). If I can, then I
download them. If I can't, I assume the computer is not connected to the
Internet and I skip the update phase.

The problem with just running urllib.urlretrieve() is that the execution
of the script halts as there is no timeout available for Python 2.2.2. (I
tried timeoutsocket.py to get this done, but that only worked on Windows
2000, not Redhat Linux 7.0. I also tried upgrading to Python 2.3, but that
caused some other problems, especially with the gettext module and with
the fact that my ISO-8859-1 encoded files needed a "coding" line.)

So that's that. Anybody still got a few lines of code that would get this
done on Python 2.2.2 on Windows _and_ Linux?

Cheers,

/Mickel G.

--
Mickel Grönroos, application specialist, linguistics, Research support, CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi





More information about the Python-list mailing list