Sha256: d92c70e09b88e6aa2cf83a4ad5b163cc5434f42ca31f471012d02dae617d95c1

Contents?: true

Size: 940 Bytes

Versions: 4

Compression:

Stored size: 940 Bytes

Contents

# frozen_string_literal: true

require "passive_circl"

module Ukemi
  module Services
    class CIRCL < Service
      private

      def config_keys
        %w(CIRCL_PASSIVE_USERNAME CIRCL_PASSIVE_PASSWORD)
      end

      def api
        @api ||= PassiveCIRCL::API.new
      end

      def lookup_by_domain(data)
        passive_dns_lookup(data, "rdata")
      end

      def lookup_by_ip(data)
        passive_dns_lookup(data, "rrname")
      end

      def passive_dns_lookup(data, key = nil)
        results = api.dns.query(data)
        results = results.select do |result|
          result.dig("rrtype") == "A"
        end

        results.map do |result|
          Record.new(
            data: result.dig(key),
            first_seen: Time.at(result.dig("time_first")).to_date.to_s,
            last_seen: Time.at(result.dig("time_last")).to_date.to_s,
            source: name
          )
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ukemi-0.4.0 lib/ukemi/services/circl.rb
ukemi-0.3.0 lib/ukemi/services/circl.rb
ukemi-0.2.0 lib/ukemi/services/circl.rb
ukemi-0.1.0 lib/ukemi/services/circl.rb