加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何确定c#中的dns变化?

发布时间:2020-12-15 21:42:05 所属栏目:百科 来源:网络整理
导读:我想监视dns地址的变化.所以我需要跟踪dns的变化.我正在用线程做它现在.我得到dns并保存文件,然后我每10秒比较一次,但我需要更具体的解决方案.例如,那有什么事吗? 这是代码: GetDns: public Liststring GetDns() { Liststring dns = new Liststring(); Ne
我想监视dns地址的变化.所以我需要跟踪dns的变化.我正在用线程做它现在.我得到dns并保存文件,然后我每10秒比较一次,但我需要更具体的解决方案.例如,那有什么事吗?
这是代码:

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;
    }

这是比较:

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] );
                    }));
                }
        }

解决方法

DNS是基于请求的. DNS服务器到客户端没有任何事件.您可以使用TTL(生存时间)元数据,该元数据会告诉您DNS记录何时到期.

这是一个库,它公开API来查询给定的dns服务器SimpleDNS以及获取TTL value的文档.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读