我想监控dns地址的变化。所以我需要跟踪 dns 的变化。我现在正在用线程做。我得到 dns 并将其保存文件,然后我每 10 秒比较一次,但我需要更具体的解决方案。例如,有什么活动吗?这是代码:
获取域名:
public List<string> GetDns()
{
List<string> dns = new List<string>();
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface networkInterface in networkInterfaces)
{
if (networkInterface.OperationalStatus == OperationalStatus.Up)
{
IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();
IPAddressCollection dnsAddresses = ipProperties.DnsAddresses;
foreach (IPAddress dnsAdress in dnsAddresses)
{
dns.Add(dnsAdress.ToString());
}
}
}
return dns;
}
这是比较:
string[] xmlDns = xmlData.GetDatas("DNSs", "Dns");
List<string> dns = getData.GetDns();
for (int i = 0; i < xmlDns.Length; i++)
{
if ( xmlDns[i].Equals( dns[i]))
{
this.Invoke(new MethodInvoker(delegate()
{
listBoxCheck.Items.Add(xmlDns[i] + " DNS was not changed.");
}));
}
else
{
this.Invoke(new MethodInvoker(delegate()
{
listBoxCheck.Items.Add(xmlDns[i] + " DNS adress was changed as " + dns[i] );
}));
}
}