Windows 如何获取本机网络连接状态

xiaoxiao2021-02-28  99

监测本地机器的网络连接状态:

#include "stdafx.h" #include "windows.h" #include <Sensapi.h> #include <iostream> #include <Wininet.h> #pragma comment(lib, "Sensapi.lib") #pragma comment(lib, "Wininet.lib") using namespace std; int _tmain() { do { //IsNetworkAlive DWORD dw; BOOL isConnect = ::IsNetworkAlive( &dw ); if(isConnect) cout << "IsNetworkAlive连接" <<endl; else cout << "IsNetworkAlive未连接" <<endl; //InternetGetConnectedState DWORD dw2; BOOL ret = InternetGetConnectedState(&dw2, 0); if (ret) cout << "InternetGetConnectedState连接" <<endl; else cout << "InternetGetConnectedState未连接" <<endl; //InternetCheckConnection BOOL bConnected = InternetCheckConnection(_T("http://www.baidu.com"), FLAG_ICC_FORCE_CONNECTION, 0); if (bConnected) cout << "InternetCheckConnection连接" <<endl; else cout << "InternetCheckConnection未连接" <<endl; //IsDestinationReachable(_T("http://www.google.com"), ) } while (FALSE); getchar(); return 1; }

转载请注明原文地址: https://www.6miu.com/read-41430.html

最新回复(0)