I want to monitor the dns address changes. So i need to track dns changes. I am doing it with thread right now. I get dns and save it file and then i compare they every 10 sec but i need more specific solution. For exampe, is there any event for that? This is the code:
GetDns:
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;
}
This is the compare:
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] );
}));
}
}