class PassiveDNS::Client
coodinates the lookups accross all configured PassiveDNS providers
coodinates the lookups accross all configured PassiveDNS providers
Constants
- DEFAULT_CONFIG_FILE
-
default location of the configuration file
- RRTYPES
-
the record types that are reported
- VERSION
-
version of
PassiveDNS::Client
Public Class Methods
Source
# File lib/passivedns/client.rb, line 69 def self.load_config(configfile = DEFAULT_CONFIG_FILE) unless File.exist? configfile warn "Could not find config file at #{configfile}. Using a blank configuration." return {} end IniParse.parse(File.read(configfile)).to_hash rescue IniParse::IniParseError => e raise "Unable to parse the config file #{configfile}: #{e.message}" end
reads an INI-style configuration file and returns a hash of section name to a hash of settings. A missing file yields an empty configuration and a warning.
Source
# File lib/passivedns/client.rb, line 83 def initialize(pdns = self.class.provider_names, configfile = DEFAULT_CONFIG_FILE) config = self.class.load_config configfile class_map = PassiveDB.providers.to_h { |provider| [provider.config_section_name, provider] } @pdnsdbs = pdns.uniq.map do |name| # rubocop:disable Performance/ChainArrayAllocation raise "Unknown Passive DNS provider: #{name}" unless class_map[name] class_map[name].new(config[name] || {}) end end
instantiate and configure all specified PassiveDNS providers pdns array of passivedns provider names, e.g., [“dnsdb”,“virustotal”] configfile filename of the passivedns-client configuration
Source
# File lib/passivedns/client.rb, line 61 def self.provider_names names = PassiveDB.providers.map(&:config_section_name) names.sort! names end
the names of all available providers, e.g., [“circl”, “dnsdb”, …]
Public Instance Methods
Source
# File lib/passivedns/client.rb, line 95 def debug=(value) @pdnsdbs.each do |pdnsdb| pdnsdb.debug = value end end
set the debug flag
Source
# File lib/passivedns/client.rb, line 109 def query(item, limit = nil) threads = @pdnsdbs.map do |pdnsdb| Thread.new item do |q| Thread.current.report_on_exception = false pdnsdb.lookup q, limit end end results = [] threads.each do |thr| thr.value&.each do |r| results << r if RRTYPES.include? r.rrtype end rescue StandardError => e # one failing provider should not lose the answers from the others warn "ERROR: #{e.message}" end results end
perform the query lookup accross all configured PassiveDNS providers
Source
# File lib/passivedns/client.rb, line 102 def timeout=(value) @pdnsdbs.each do |pdnsdb| pdnsdb.timeout = value end end
set the timeout, in seconds, for each provider’s lookups