网络状态检测方法测试结果
2015-04-13 15:05
369 查看
1 IsInternetConnected
2 InetIsOffline
3 InternetAttemptConnect
4 InternetCheckConnection
5 InternetQueryOption
6 InternetGetConnectedState
二、测试环境
NET: Company LAN
PC: EeePC 1005H
三:测试Code
#include <Windows.h>
#include <WinInet.h>
// Lib
#pragma comment(lib,"wininet.lib")
// Internet Status Include
#include "InternetStatus.h"
#include <IntShCut.h>
typedef BOOL (__stdcall *FUN)(DWORD);
FUN isOffLine;
// =================================================================== NetWork Status
int _tmain(int argc, _TCHAR* argv[])
{
// InternetOpen() method Test
OutputDebugString(TEXT("\r\n=======1=========InternetOpen() Method Test Result: \r\n\n"));
if (IsInternetConnected())
{
OutputDebugString(TEXT("\r\n Internet Connected ~_~ \r\n"));
}
else
{
OutputDebugString(TEXT("\r\n Internet Not Connected! \r\n"));
}
OutputDebugString(TEXT("\r\n=======1=========InternetOpen() Method Test Result: \r\n\n"));
// InetIsOffline() method Test
OutputDebugString(TEXT("\r\n=======2=========InetIsOffline() Method Test Result: \r\n\n"));
HINSTANCE hDll = LoadLibrary(TEXT("C:\\WINDOWS\\system32\\url.dll"));
if (hDll == NULL)
{
OutputDebugString(TEXT("LoadLibrary Errror:: \r\n"));
goto EndLoadDll;
}
isOffLine = (FUN)GetProcAddress(hDll, "InetIsOffline");
if (isOffLine == NULL)
{
OutputDebugString(TEXT("GetProcAddress Errror:: \r\n"));
goto EndLoadDll;
}
if (!isOffLine(0))
{
OutputDebugString(TEXT("Internet Connected ~_~ \r\n"));
}
else
{
OutputDebugString(TEXT("Internet Not Connected! \r\n"));
}
EndLoadDll:
if (hDll)
{
FreeLibrary(hDll);
}
OutputDebugString(TEXT("\r\n=======2=========InetIsOffline() Method Test Result: \r\n\n"));
// InternetAttemptConnect() Test
OutputDebugString(TEXT("\r\n=======3=========InternetAttemptConnect() Method Test Result: \r\n\n"));
TCHAR tszDebugMsg[100] = {0};
DWORD dwres = InternetAttemptConnect(0);
if (dwres != ERROR_SUCCESS )
{
_stprintf_s(tszDebugMsg, 100, TEXT("InternetAttemptConnect failed error code is %d.\r\n"), dwres);
}
else
{
_stprintf_s(tszDebugMsg, 100, TEXT("Internet Connected ~_~ (not consider connect mode)\r\n"));
}
OutputDebugString(tszDebugMsg);
OutputDebugString(TEXT("\r\n=======3=========InternetAttemptConnect() Method Test Result: \r\n\n"));
// InternetCheckConnection() Method Test
OutputDebugString(TEXT("\r\n=======4.1=========InternetCheckConnection() Method Test Result: \r\n\n"));
BOOL bres = InternetCheckConnection(TEXT("https://vip.asus.com/"), FLAG_ICC_FORCE_CONNECTION, 0);
if (!bres)
{
_stprintf_s(tszDebugMsg, 100, TEXT("InternetCheckConnection asus failed error code is %d.\r\n"), GetLastError());
}
else
{
_stprintf_s(tszDebugMsg, 100, TEXT("Internet Connected asus ~_~ (physical connect sucess)\r\n"));
}
OutputDebugString(tszDebugMsg);
OutputDebugString(TEXT("\r\n=======4.1=========InternetCheckConnection() Method Test Result: \r\n\n"));
// InternetCheckConnection() Method Test
OutputDebugString(TEXT("\r\n=======4.2=========InternetCheckConnection() Method Test Result: \r\n\n"));
bres = InternetCheckConnection(TEXT("https://www.baidu.com/"), FLAG_ICC_FORCE_CONNECTION, 0);
if (!bres)
{
_stprintf_s(tszDebugMsg, 100, TEXT("InternetCheckConnection baidu failed error code is %d.\r\n"), GetLastError());
}
else
{
_stprintf_s(tszDebugMsg, 100, TEXT("Internet Connected baidu ~_~ (physical connect sucess)\r\n"));
}
OutputDebugString(tszDebugMsg);
OutputDebugString(TEXT("\r\n=======4.2=========InternetCheckConnection() Method Test Result: \r\n\n"));
// InternetQueryOption() Metho
b421
d Test
OutputDebugString(TEXT("\r\n=======5=========InternetQueryOption() Method Test Result: \r\n\n"));
BYTE btInetSet[100] = {0};
DWORD dwInetSetLen = 100;
bres = InternetQueryOption(NULL, INTERNET_OPTION_CONNECTED_STATE, btInetSet, &dwInetSetLen);
if (!bres)
{
_stprintf_s(tszDebugMsg, 100, TEXT("InternetQueryOption failed error code is %d.\r\n"), GetLastError());
}
else
{
_stprintf_s(tszDebugMsg, 100, TEXT("Internet Connected ~_~ (can get Internet service, internet settting ok) \r\n"));
}
OutputDebugString(tszDebugMsg);
OutputDebugString(TEXT("\r\n=======5=========InternetQueryOption() Method Test Result: \r\n\n"));
// InternetGetConnectedState() Method Test
OutputDebugString(TEXT("\r\n=======6=========InternetGetConnectedState() Method Test Result: \r\n\n"));
DWORD dwFlags;
bres = InternetGetConnectedState(&dwFlags, 0);
if (!bres)
{
_stprintf_s(tszDebugMsg, 100, TEXT("InternetGetConnectedState failed error code is %d.\r\n"), GetLastError());
}
else
{
_stprintf_s(tszDebugMsg, 100, TEXT("Internet Connected ~_~ (sucess status is 0x%x) \r\n"),dwFlags);
}
OutputDebugString(tszDebugMsg);
OutputDebugString(TEXT("\r\n=======6=========InternetGetConnectedState() Method Test Result: \r\n\n"));
system("pause");
return 0;
}
相关文章推荐
- 网络状态检测方法分析
- iOS 检测网络状态的2个方法
- 检测网络状态的方法
- iOS两种检测网络状态的方法
- IOS(SystemConfiguration)框架中关于测试连接网络状态相关方法
- Visual Basic.net 检测网络连接状态的两种方法
- Apple 的例程 Reachability 中介绍了取得检测网络状态的方法
- Android,检测网络状态的方法
- 网络连接状态检测的一个方法
- Android弱网测试中关于网络检测的一些借鉴方法
- 网络状态检测方法分析
- 检测本地网络连接状态断开以及恢复的方法
- 网络状态检测方法分析
- C# ping网络IP 实现网络状态检测的方法
- qt检测网络连接状态【只能检测和路由器的连接,不能测试到外网的连接】
- IOS(SystemConfiguration)框架中关于测试连接网络状态相关方法
- iOS 检测网络状态的两种方法
- qt检测网络连接状态【只能检测和路由器的连接,不能测试到外网的连接】
- iOS开发 - Swift实现检测网络连接状态及网络类型
- ios 开发之使用Reachability检测网络状态