Checking if the computer is online
Mickel Grönroos
mickel at csc.fi
Thu Sep 18 05:27:49 EDT 2003
On Thu, 18 Sep 2003, Thomas Heller wrote:
> Mickel Grönroos <mickel at csc.fi> writes:
>
> > On Thu, 18 Sep 2003, Thomas Heller wrote:
> >
> >> Mickel Grönroos <mickel at csc.fi> writes:
> >>
> >> > 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.
> >>
> >> For windows?
> >>
> >> <http://article.gmane.org/gmane.comp.python.windows/969>
> >
> > I want to get this done on both Windows (2000/XP) and (Redhat) Linux (7.x
> > or higher).
> >
> > Isn't there a way to wrap a call to urllib.urlopen in some kind of timer,
> > so that the call fails if there is no answer in N seconds? (I.e. if
> > urllib.urlopen cannot open a specific web page in N seconds, then I
> > assume that the reason is that the computer is not online.) That would be
> > good enough for me. Any suggestions?
>
> Of course you can do it this way. Or even simpler with the socket
> module.
You wouldn't have some sample code on how I can use the socket module to
test if I can connect to a given URL? (I would't want to rely on other
modules than the ones in the standard library, so therefore I want to
try this socket approach.)
Cheers,
/Mickel
More information about the Python-list
mailing list