win32

两种方法:

第一种是使用WMI进行后台轮询

第二种是查询注册表对应的DNS键值

Here: HKLMSYSTEMCurrentControlSetServicesTcpipParametersInterfaces[interface-name]

使用RegNotifyChangeKeyValue进行监控

顺便一提:

想要监控主机的IP地址,子网掩码或默认网关是否更改,可以使用NotifyRouteChange或者NotifyIpInterfaceChange 来发送通知。

一些代码:

#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <windows.h>

#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")

void main()
{
  OVERLAPPED overlap;
  DWORD ret;
    
  HANDLE hand = NULL;
  overlap.hEvent = WSACreateEvent();

  ret = NotifyRouteChange(&hand, &overlap);

  if (ret != NO_ERROR)
  {
    if (WSAGetLastError() != WSA_IO_PENDING)
    {
      printf("NotifyRouteChange error...%d
", WSAGetLastError());            
      return;
    }
  }

  if ( WaitForSingleObject(overlap.hEvent, INFINITE) == WAIT_OBJECT_0 )
    printf("Routing table changed..
");
}
原文地址:https://www.cnblogs.com/strive-sun/p/13800978.html