Sha256: 5bc71129c07241b5401e0384eb71e21373cdc277b0ff70dcaec75456fd03ecca

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "date"
require "dnsdb"

module Ukemi
  module Services
    class DNSDB < Service
      private

      def config_keys
        %w(DNSDB_API_KEY)
      end

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

      def lookup_by_ip(data)
        results = api.lookup.rdata(type: "ip", value: data, rrtype: "A")
        results.map do |result|
          rrname = result.dig("rrname")
          # Remove the last dot (e.g. "example.com.")
          data = rrname[0..-2]
          Record.new(
            data: data,
            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

      def lookup_by_domain(data)
        results = api.lookup.rrset(owner_name: data, rrtype: "A")
        results.map do |result|
          first_seen = Time.at(result.dig("time_first")).to_date.to_s
          last_seen = Time.at(result.dig("time_last")).to_date.to_s

          values = result.dig("rdata") || []
          values.map do |value|
            Record.new(
              data: value,
              first_seen: first_seen,
              last_seen: last_seen,
              source: name
            )
          end
        end.flatten
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ukemi-0.4.0 lib/ukemi/services/dnsdb.rb
ukemi-0.3.0 lib/ukemi/services/dnsdb.rb