Checking if the computer is online
theller at python.net
Thu Sep 18 10:56:32 CEST 2003
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?
> 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
But it depends on what you exactly want:
It's been quite a time that I had a dial-up connection, but IIRC,
trying network activity when the computer was not connected would result
in Windows trying to establish the connection.
To conclude: the above mentioned URL contains code which exactly answers
your original question.
More information about the Python-list