示例#1
0
        private double FindHostnameSimilarity(Query query, DnsRule rule)
        {
            var hostnames = rule.Hostnames;
            if (query.QueryType != DnsRecordType.CNAME && query.QueryType != DnsRecordType.A)
            {
                if (hostnames.Any(hostname => hostname.HostnameType == HostnameType.Exact && hostname.HostnameEntry == query.Question))
                {
                    return 1;
                }
                return 0;
            }

            if (hostnames.Any(hostname => hostname.HostnameType == HostnameType.Exact && hostname.HostnameEntry == query.Question))
            {
                return 1;
            }

            if (hostnames.Any(hostname => hostname.HostnameType == HostnameType.Wildcard && query.Question.EndsWith(hostname.HostnameEntry)))
            {
                return 0.9;
            }

            return 0;
        }
示例#2
0
 public void AddRule(DnsRule dnsRule)
 {
     _dnsRules.Add(dnsRule);
 }
示例#3
0
        private double SimilarRuleTypes(Query query, DnsRule rule)
        {
            if (rule.RuleType.HasValue && (rule.RuleType.Value == DnsRuleType.NXDomain || rule.RuleType.Value == DnsRuleType.ResolveUpstream))
            {
                return 0.1;
            }

            if (rule.RecordType == query.QueryType)
            {
                return 1;
            }

            if (query.QueryType == DnsRecordType.A && rule.RecordType == DnsRecordType.CNAME)
            {
                return 0.9;
            }

            return 0;
        }