InternetCheckConnection 通过尝试连接特定的网址,可以用来判断目前机器是否接通外网
2014-12-24 14:46
465 查看
InternetCheckConnection 通过尝试连接特定的网址,可以用来判断目前机器是否接通外网。例如:
BOOL bConnected = InternetCheckConnection(_T("http://www.google.com"), FLAG_ICC_FORCE_CONNECTION, 0);
使用时第二个参数一定要设置为FLAG_ICC_FORCE_CONNECTION,这样才会尝试去建立连接。当目标地址不可用时,这个函数返回会比较慢,注意不要在UI线程中使用。
这个函数会解析出URL中的host地址,然后建立socket连接去ping这个地址。
Allows an application to check if a connection to the Internet can be established.
lpszUrl[in] Pointer to a null-terminated string that specifies the URL to use to check the connection. This value can be NULL.dwFlags[in] Options. FLAG_ICC_FORCE_CONNECTION is the only flag that is currently available. If this flag is set, it forces a connection. A sockets connection is attempted in the following order:
If lpszUrl is non-NULL, the host value is extracted from it and used to ping that specific host.
If lpszUrl is NULL and there is an entry in the internal server database for the nearest server, the host value is extracted from the entry and used to ping that server.
dwReserved[in] Reserved. Must be zero.
Returns TRUE if
a connection is made successfully, or FALSE otherwise. Use GetLastError to
retrieve the error code. ERROR_NOT_CONNECTED is returned by GetLastError if a
connection cannot be made or if the sockets database is unconditionally offline.
BOOL bConnected = InternetCheckConnection(_T("http://www.google.com"), FLAG_ICC_FORCE_CONNECTION, 0);
使用时第二个参数一定要设置为FLAG_ICC_FORCE_CONNECTION,这样才会尝试去建立连接。当目标地址不可用时,这个函数返回会比较慢,注意不要在UI线程中使用。
这个函数会解析出URL中的host地址,然后建立socket连接去ping这个地址。
InternetCheckConnection
Allows an application to check if a connection to the Internet can be established.<strong>BOOL InternetCheckConnection( LPCTSTR</strong> <em><a target=_blank class="synParam" href="http://blog.csdn.net/harbinzju/article/details/6956814" style="color: rgb(202, 0, 0); text-decoration: none;">lpszUrl</a></em><strong>, DWORD</strong> <em><a target=_blank class="synParam" href="http://blog.csdn.net/harbinzju/article/details/6956814" style="color: rgb(202, 0, 0); text-decoration: none;">dwFlags</a></em><strong>, DWORD</strong> <em><a target=_blank class="synParam" href="http://blog.csdn.net/harbinzju/article/details/6956814" style="color: rgb(202, 0, 0); text-decoration: none;">dwReserved</a></em><strong> );</strong>
Parameters
lpszUrl[in] Pointer to a null-terminated string that specifies the URL to use to check the connection. This value can be NULL.dwFlags[in] Options. FLAG_ICC_FORCE_CONNECTION is the only flag that is currently available. If this flag is set, it forces a connection. A sockets connection is attempted in the following order:If lpszUrl is non-NULL, the host value is extracted from it and used to ping that specific host.
If lpszUrl is NULL and there is an entry in the internal server database for the nearest server, the host value is extracted from the entry and used to ping that server.
dwReserved[in] Reserved. Must be zero.
Return Values
Returns TRUE ifa connection is made successfully, or FALSE otherwise. Use GetLastError to
retrieve the error code. ERROR_NOT_CONNECTED is returned by GetLastError if a
connection cannot be made or if the sockets database is unconditionally offline.
相关文章推荐
- 用InternetCheckConnection 判断是否接通外网
- android 判断是否真正连接到internet(通过检测网址,需要时间)
- Android检查设备是否可以访问互联网,判断Internet连接,测试网络请求,解析域名
- 判断当前机器是否连接到Internet
- java中可以通过调用ping命令来判断网络是否连接正常
- [笔记]一道C语言面试题:判断字串是否可以通过重新排列字母使之对称
- (转)检测计算机的 Internet 连接状态(InternetCheckConnection与InternetQueryOption)
- 判断计算机是否已经连接到Internet
- 判断是否连接到Internet
- 实时检测网络状态及是否可以连接Internet
- Android检查Internet是否可以正常连接
- C# 判断是否可以连接服务器?
- 实时检测网络状态及是否可以连接Internet
- 客服端的状态保持。可以用来判断用户是否存在或者购物车等信息
- VirtualBox安装Centos,配置网络(主机可以通过SSH连接虚拟机系统,同时虚拟机系统可以访问外网)
- JAVA--第十周作业编写之一个Teacher类负责给出算术题目,随机给出两个整数并进行运算,并判断回答者的答案是否正确;编写一个GUI类ComputerFrame,回答者可以通过GUI看到题目并给出
- c#通过Windows API 判断网络是否连接
- PB使用WININET的FTP方式自动更新(二、判断是否可以连接)
- C# 利用【wininet.dll】判断是否能够连接到Internet
- [笔记]一道C语言面试题:判断字串是否可以通过重新排列字母使之对称