如何检测到计算机是否online,offline

edwardyi 2000-03-30 06:21:00
如何检测到计算机是否online,offline
...全文
273 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Un1 2000-03-31
  • 打赏
  • 举报
回复
SoftDIY:
如果是通过局域网上网怎么办?
SoftDIY 2000-03-31
  • 打赏
  • 举报
回复
既是上网记费软件,就是针对拨号用户了,try the code
BOOL CYouSApp::IsRASConnected() //code by softdiy
{
RASCONN rasconn;
DWORD dNumber,dSize ;
rasconn.dwSize = sizeof(RASCONN);
dSize = sizeof(rasconn);
if (RasEnumConnections(&rasconn,&dSize,&dNumber)!=0)
return false;
if (dNumber==0)
return false;
return true;
}

Softdoctor,InternetAttemptConnect只是监测ie是否选了脱机,没有在线监测
SoftDIY 2000-03-31
  • 打赏
  • 举报
回复
关于no define error,请include相关头文件。ras函数同时还须input ras的lib文件
拨号对话框可以玩个虚的,InternetOpenURL就可以弹出缺省对话框

SoftDIY 2000-03-31
  • 打赏
  • 举报
回复
贴上一篇msdn的howto,url是http://support.microsoft.com/support/kb/articles/Q242/5/58.ASP

HOWTO: Detecting If You Have a Connection to the Internet

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 4.01 SP1, 4.01 SP2, 5

--------------------------------------------------------------------------------


SUMMARY
Many of you want to know if a computer has an active Internet connection before trying to connect to the Internet using the WinInet API or some other communication interface. The internet connection is important if you don't want your application to cause Windows to automatically dial the default Internet modem connection.

This article provides a mechanism for determining if an Internet site is accessible without the risk of you being prompted to dial into another Internet Service Provider.



MORE INFORMATION
Usually the best way to determine if you have a connection to a particular computer is to attempt the connection. If the autodial feature of Windows is enabled then attempting the connection may cause the default Internet dialup connectoid to be opened, and you will be prompted with your credentials to connect.

To avoid having the default Internet connectoid dialed, the InternetGetConnectedState function can be used to determine if there is a default Internet dialup connectoid configured and whether it is currently active or not. If there is a default Internet dialup connectoid configured and it is not currently active then InternetGetConnectedState will return FALSE. If InternetGetConnectedState returns TRUE then you can attempt to connect to the Internet resource without fear of being prompted to connect to another Internet Service Provider.

The following code demonstrates how you would do this:


if (InternetGetConnectedState(...) == FALSE)
{
// Don't attempt connection or it will bring up the dialog
...
}
else
{
//Attempt connection
if (InternetOpenURL(...) == NULL)
{
// Call failed
err = GetLastError();
if ((err == ERROR_INTERNET_NAME_NOT_RESOLVED) and and
(err == ERROR_INTERNET_CANNOT_CONNECT) and and
(err == ERROR_INTERNET_TIMEOUT))
{
// probably not connected...handle appropriately
...
}
}
// We're connected!!!
....
}


You cannot rely solely on the fact that InternetGetConnectedState returning TRUE means that you have a valid active Internet connection. It is impossible for InternetGetConnectedState to determine if the entire connection to the Internet is functioning without sending a request to a server. This is why you need to send a request to determine if you are really connected or not. You can be assured however that if InternetGetConnectedState returns TRUE, that attempting your connection will NOT cause you to be prompted to connect to the default Internet Service Provider.

Be aware that InternetGetConnectedState only reports the status of the default Internet connectoid on Internet Explorer 4.x. If a nondefault connectoid is connected, InternetGetConnectedState always returns FALSE (unless a LAN connection is used). With Internet Explorer 4.x configured to use a LAN connection, InternetGetCo nectedState always returns TRUE.

Internet Explorer 5 behaves differently. If you are currently dialed into a different dial-up in Internet Explorer 5, InternetGetConnectedState reports dial-up connection status as long as any connectoid is dialed or an active LAN connection exists.

There are some other ways to try to determine if you currently have a connection to a particular network resource. The IsDestinationReachable() function can be used to find out if there is a current connection to an address. However, he IsDestinationReachable() function is only concerned with whether the IP address is reachable from your computer. It does not work through HTTP proxies or firewalls that restrict ICMP ping packets.

It is also possible to use RasEnumConnections to enhance your code so that you can tell if there is an active dialup connection that might have Internet access even though it is not the default Internet dialup connectoid.

Additional query words:

Keywords : kbIE kbIE400 kbIE401sp1 kbIE401sp2 kbIE500 kbGrpInetServer kbDSupport kbIEFAQ
Version : WINDOWS:4.0,4.01,4.01 SP1,4.01 SP2,5
Platform : WINDOWS
Issue type : kbhowto
edwardyi 2000-03-31
  • 打赏
  • 举报
回复
为何我用RasEnumConnections,InternetAttemptConnect等函数
时总是报错(undefined identifier),是需要包什头文件呢,还是缺少dll?另外请教怎样调出windows下的拨号对话框?谢谢各位的鼎立帮助!
olo 2000-03-31
  • 打赏
  • 举报
回复
我也想知道局域网怎么办。
edwardyi 2000-03-30
  • 打赏
  • 举报
回复
我想写一个上网记费软件,能否更详细的说明
edwardyi 2000-03-30
  • 打赏
  • 举报
回复
please introduce it in detail
softdoctor 2000-03-30
  • 打赏
  • 举报
回复
使用API 函数 InternetAttemptConnect
很容易的。
if(InternetAttemptConnect(0)==ERROR_SUCCESS)
{
// 在线
}
else
{
//离线
}
tide 2000-03-30
  • 打赏
  • 举报
回复
可以检测注册表。具体键值忘了,可以用regmon监视一下。
kxy 2000-03-30
  • 打赏
  • 举报
回复
用PING
www.midatech.com/kxy有ping的soure (VC的)
WHQ 2000-03-30
  • 打赏
  • 举报
回复
InternetGetConnectedState/InternetGetConnectedStateEx
Lin 2000-03-30
  • 打赏
  • 举报
回复
向指定计算机发ICMP包,看有否回应。
BareHead 2000-03-30
  • 打赏
  • 举报
回复
用windows socket api,在两台计算机间建立tcp/ip的socket连接,就可以检测online还是offline了
BNUEP Offline Judge 北京师范大学珠海分校离线评测系统是在具备题目测试数据的情况下,能无联网自动评测ACM/ICPC模式的源代码评测系统(即本地测试工具、评测机)。它主要有以下功能(所有的功能都无需联网,在本机即可实现): *评测核心功能: 基本具备Online Judge的判题核心功能,如编译代码、内存限定,时间限定,获取代码长度等; *支持多种语言: 1.0 Beta2版本支持C/C++、Pascal、C#、JAVA; *出题模式 可以在有标准输入数据和标准程序的情况下,由系统产生标准输出数据,并可批量保存,同时自动命名标准输出数据的后缀; *文本高亮对比 在判题后,可以直接在本系统中将自己的程序输出和标准输出进行高亮的文本差异对比,操作类似于一些文本对比软件,在一定程度上可以较方便地发现WA代码的出错细节; *支持不限时执行代码 这个功能可以在一定程度上检测TLE代码的算法是否正确的,当然,不能是跑一天都没跑出来的程序; *打包与加密测试数据 使用加密后的数据可以正常判题,但不显示标准输出。这个功能是为了弥补放出去给别人评测的测试数据是明文的缺陷。加密之后评测方就看不到测试数据。这样就既可以实现离线评测,又可以实现Online Judge上的对测试数据屏蔽; ACM-ICPC简介: ACM国际大学生程序设计竞赛(简称ACM-ICPC)是由国际计算机界具有悠久历史的权威性组织ACM学会(Association for Computing Machinery)主办,是世界上公认的规模最大、水平最高、参与人数最多的大学生程序设计竞赛,其宗旨是使大学生能通过计算机充分展示自己分析问题和解决问题的能力。 ACM-ICPC的每一道题,都具备题目、需求描述、输入格式描述、输出格式描述、样例输入和样例输出共六大信息,有些题目还有一定的提示。此外,裁判还额外存储了关于该题的一组或多组对选手屏蔽的标准输入和标准输出数据,这些测试数据已经经过验证符合题意要求。当用户提交一道题目的源码之后,裁判会将该源码放入评测系统中编译运行,并使用标准输入作为用户程序的输入,然后获取用户程序的输出,接着,将用户程序输出和标准输出比较,最后返回给用户一个评判结果。评判结果包括:Accepted(测试通过)、Compile Error(编译失败)、Memory Limit Exceed(内存超出限制)、Presentation Error(格式错误)、Runtime Error(运行时错误,可能是数组越界,改写只读的内存,除零,栈或堆溢出等错误)、Time Limit Exceed(时间超出限制)、Wrong Answer(答案错误)等。

16,470

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧