检查计算机是否在线 [英] Checking if the computer is online

查看:90
本文介绍了检查计算机是否在线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个愚蠢的问题。是否有简单的方法来检查计算机是否连接到互联网?看起来这应该是一个非常好的b / b
直接做的事情,但由于我完全不熟悉套接字

等等,所以在得到我的手之前我会请求你的帮助很脏。


干杯,


Mickel G.


-

Mickel Gr?nroos,应用专家,语言学,研究支持,CSC

PL 405(Tekniikantie 15 a D),02101 Espoo,芬兰,电话+ 358-9-4572237

CSC是芬兰的IT科学中心, www.csc.fi

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.

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

推荐答案

Mickel Gr?nroos< mi **** @ csc.fi>写道:
Mickel Gr?nroos <mi****@csc.fi> writes:
大家好,

我有一个愚蠢的问题。是否有简单的方法来检查计算机是否已连接到Internet?看起来这应该是一个非常直接的事情,但由于我完全不熟悉套接字
等等,所以在弄脏之前我会请求你的帮助。
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.




对于Windows?


< http://article.gmane.org/gmane.comp.python.windows/969>


Thomas



For windows?

<http://article.gmane.org/gmane.comp.python.windows/969>

Thomas


2003年9月18日星期四,Thomas Heller写道:
On Thu, 18 Sep 2003, Thomas Heller wrote:
Mickel Gr ?nroos< mi **** @ csc.fi>写道:
Mickel Gr?nroos <mi****@csc.fi> writes:
大家好,

我有一个愚蠢的问题。是否有简单的方法来检查计算机是否已连接到Internet?看起来这应该是一个非常直接的事情,但由于我完全不熟悉套接字
等等,所以在弄脏之前我会请求你的帮助。
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.



对于Windows?

< http://article.gmane.org/gmane.comp.python.windows/969>



For windows?

<http://article.gmane.org/gmane.comp.python.windows/969>



我想在Windows(2000 / XP)和(Redhat)Linux(7.x

或更高)上完成这项工作。


有没有办法在某种计时器中包含对urllib.urlopen的调用,

如果N秒内没有答案则调用失败? (即如果

urllib.urlopen无法在N秒内打开特定网页,那么我

假设原因是计算机不在线。)那将是

对我来说足够好。有什么建议吗?


/ Mickel



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?

/Mickel


Mickel Gr?nroos< mi **** @ csc。 Fi无线网络和GT;写道:
Mickel Gr?nroos <mi****@csc.fi> writes:
2003年9月18日星期四,Thomas Heller写道:
On Thu, 18 Sep 2003, Thomas Heller wrote:
Mickel Gr?nroos< mi **** @ csc .fi>写道:
Mickel Gr?nroos <mi****@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.



对于Windows?

< http://article.gmane.org/gmane .comp.python.windows / 969>



For windows?

<http://article.gmane.org/gmane.comp.python.windows/969>



我想在Windows(2000 / XP)和(Redhat)Linux(7.x
或更高版本)上完成此操作)。

是不是有办法在某种计时器中调用urllib.urlopen的调用,
如果在N秒内没有答案,则调用失败? (即如果
urllib.urlopen无法在N秒内打开特定的网页,那么我认为原因是计算机不在线。)这对我来说足够好了。 。有什么建议吗?



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?




当然你可以这样做。甚至更简单的插座

模块。


但这取决于你到底想要什么:

它已经被很长一段时间我都有拨号连接,但IIRC,

在计算机没有连接的情况下尝试网络活动会导致Windows尝试建立连接时的



总结:上面提到的URL包含完全回答的代码

你的原始问题。


Thomas



Of course you can do it this way. Or even simpler with the socket
module.

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.

Thomas


这篇关于检查计算机是否在线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆