<commit_before># frozen_string_literal: true

class SiteInspector
  class Endpoint
    class Dns < Check
      class LocalhostError < StandardError; end

      def self.resolver
        require 'dnsruby'
        @resolver ||= begin
          resolver = Dnsruby::Resolver.new
          resolver.config.nameserver = ['1.1.1.1', '192.168.3.11']
          resolver
        end
      end

      def query(type = 'ANY')
        SiteInspector::Endpoint::Dns.resolver.query(host.to_s, type).answer
      rescue Dnsruby::ResolvTimeout, Dnsruby::ServFail, Dnsruby::NXDomain, Dnsruby::OtherResolvError
        []
      end

      def records
        @records ||= query
      end

      def record?(type)
        records.any? { |record| record.type == type } || query(type).count != 0
      end
      alias has_record? record?

      def dnssec?<commit_msg>use Google DNS, cloudflare doesnt support ANY queries<commit_after># frozen_string_literal: true

class SiteInspector
  class Endpoint
    class Dns < Check
      class LocalhostError < StandardError; end

      def self.resolver
        require 'dnsruby'
        @resolver ||= begin
          resolver = Dnsruby::Resolver.new
          resolver.config.nameserver = ['8.8.8.8', '8.8.4.4']
          resolver
        end
      end

      def query(type = 'ANY')
        SiteInspector::Endpoint::Dns.resolver.query(host.to_s, type).answer
      rescue Dnsruby::ResolvTimeout, Dnsruby::ServFail, Dnsruby::NXDomain, Dnsruby::OtherResolvError => e
        SiteInspector.logger.warn e.message
        []
      end

      def records
        @records ||= query
      end

      def record?(type)
        records.any? { |record| record.type == type } || query(type).count != 0
      end
      alias has_record? record?

      def dnssec?
{'fraction_non_alphanumeric': 0.10484780157835401, 'fraction_numerical': 0.012965050732807215, 'mean_word_length': 2.3054003724394785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5305464', 'n_tokens_mistral': 572, 'n_tokens_neox': 545, 'n_words': 125}