class PassiveDNS::Client

coodinates the lookups accross all configured PassiveDNS providers

coodinates the lookups accross all configured PassiveDNS providers

Constants

VERSION

version of PassiveDNS::Client

Public Class Methods

new(pdns=$passivedns_providers, configfile=" click to toggle source

instantiate and configure all specified PassiveDNS providers pdns array of passivedns provider names, e.g., [“dnsdb”,“virustotal”] configfile filename of the passivedns-client configuration (this should probably be abstracted)

# File lib/passivedns/client.rb, line 62
def initialize(pdns=$passivedns_providers, configfile="#{ENV['HOME']}/.passivedns-client")
  cp = {}
  if File.exist?(configfile)
    cp = ConfigParser.new(configfile)
  else
    $stderr.puts "Could not find config file at #{configfile}.  Using a blank configuration."
  end
  # this creates a map of all the PassiveDNS provider names and their classes
  class_map = {}
  PassiveDNS::Provider.constants.each do |const|
    if PassiveDNS::Provider.const_get(const).is_a?(Class) and PassiveDNS::Provider.const_get(const).superclass == PassiveDNS::PassiveDB
      class_map[PassiveDNS::Provider.const_get(const).config_section_name] = PassiveDNS::Provider.const_get(const)
    end
  end
  
  @pdnsdbs = []
  pdns.uniq.each do |pd|
    if class_map[pd]
      @pdnsdbs << class_map[pd].new(cp[pd] || {})
    else
      raise "Unknown Passive DNS provider: #{pd}"
    end
  end

end

Public Instance Methods

debug=(d) click to toggle source

set the debug flag

# File lib/passivedns/client.rb, line 89
def debug=(d)
  @pdnsdbs.each do |pdnsdb|
    pdnsdb.debug = d
  end
end
query(item, limit=nil) click to toggle source

perform the query lookup accross all configured PassiveDNS providers

# File lib/passivedns/client.rb, line 102
def query(item, limit=nil)
  threads = []
  @pdnsdbs.each do |pdnsdb|
    threads << Thread.new(item) do |q|
      pdnsdb.lookup(q, limit)
    end
  end
    
  results = []
  threads.each do |thr|
    rv = thr.join.value
    if rv
      rv.each do |r|
        if ["A","AAAA","NS","CNAME","PTR"].index(r.rrtype)
          results << r
        end
      end
    end
  end
  
  return results
end
timeout=(t) click to toggle source
# File lib/passivedns/client.rb, line 95
def timeout=(t)
  @pdnsdbs.each do |pdnsdb|
    pdnsdb.timeout = t
  end
end