VC 判断网络连接函数IsNetworkAlive

langshanglibie 2011-09-26 11:56:50
当我的电脑连接了局域网,但是整个局域网没有连接因特网,此函数返回TRUE吗?
也就是说IsNetworkAlive判断的是连接局域网还是因特网啊?
...全文
468 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
5t4rk 2011-09-26
  • 打赏
  • 举报
回复
局域网
酒红色的泪 2011-09-26
  • 打赏
  • 举报
回复
MSDN:
IsNetworkAlive Function

The IsNetworkAlive function determines whether or not a local system is connected to a network, and identifies the type of network connection, for example, a LAN, WAN, or both.


Syntax
Bool IsNetworkAlive(
__out LPDWORD lpdwFlags
);

Parameters
lpdwFlags
The type of network connection that is available. This parameter can be one of the following values:


NETWORK_ALIVE_LAN
The computer has one or more LAN cards that are active.

NETWORK_ALIVE_WAN
The computer has one or more active RAS connections.

NETWORK_ALIVE_AOL
This flag is not valid.

Return Value
This function returns one of the following values:

Return code Description
TRUE
A local system is connected to a network.

For information about the type of connection, see the lpdwFlags parameter.

FALSE
There is no connection.

For extended error information, call GetLastError.


Remarks
This function can be used by an application to determine whether or not there is network connectivity before proceeding with network operations. A directory service type of application, e-mail client, or Internet browser can adapt to various types of network connectivity. For example, a printing operation can be deferred until a network connection is available.

It may not always be practical for an application to call IsNetworkAlive to determine whether or not a local system is disconnected from a LAN, because IsNetworkAlive can be slow, and it may take too much time for the function to detect that a local system is disconnected. However, IsNetworkAlive can always identify a WAN connectivity at the moment.

Note This function is only available for TCP/IP connections.

如果返回值里有NETWORK_ALIVE_WAN,则说明检测到互联网连接了。
窃以为是通过连接固定的微软的某个服务器进行判断的。
oyljerry 2011-09-26
  • 打赏
  • 举报
回复
应该是局域网. 英特网需要你自己去进行http连接来判断

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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