#pragma comment(lib,"Ws2_32.lib")
#include
#pragma comment(lib, "Iphlpapi.lib")
using namespace std;
typedef struct tagNetworkCfg
{
char szIP[18];
char szNetmask[18];
char szGateway[18];
char szDns1[18];
char szDns2[18];
}NetworkCfg;
bool GetNetworkCfg(NetworkCfg *cfg)
{
log_printf("Get network config");
//获取网卡名称 网卡名称,网卡别名
string strAdapterName,strAdapterAlias;
HKEY hKey, hSubKey, hNdiIntKey;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"System\\CurrentControlSet\\Control\\Class\\{4d36e972-e325-11ce-bfc1-08002be10318}",
0,
KEY_READ,
&hKey) != ERROR_SUCCESS)
return FALSE;
DWORD dwIndex = 0;
DWORD dwBufSize = 256;
DWORD dwDataType;
char szSubKey[256];
unsigned char szData[256];
while(RegEnumKeyEx(hKey, dwInde