Class: PassiveDNS::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/passivedns/client.rb,
lib/passivedns/client/version.rb

Overview

coodinates the lookups accross all configured PassiveDNS providers

Constant Summary collapse

VERSION =

version of PassiveDNS::Client

"2.1.6"

Instance Method Summary collapse

Constructor Details

#initialize(pdns = $passivedns_providers, configfile = "#{ENV['HOME']}/.passivedns-client") ⇒ Client

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)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/passivedns/client.rb', line 30

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

Instance Method Details

#debug=(d) ⇒ Object

set the debug flag



57
58
59
60
61
# File 'lib/passivedns/client.rb', line 57

def debug=(d)
	@pdnsdbs.each do |pdnsdb|
		pdnsdb.debug = d
	end
end

#query(item, limit = nil) ⇒ Object

perform the query lookup accross all configured PassiveDNS providers



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/passivedns/client.rb', line 64

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