Class: PassiveDNS::Client

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

Constant Summary collapse

VERSION =
"2.0.3"

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/passivedns/client.rb', line 25

def initialize(pdns=$passivedns_providers, configfile="#{ENV['HOME']}/.passivedns-client")
    cp = ConfigParser.new(configfile)
    # this creates a map of all the PassiveDNS provider names and their classes
    class_map = {}
    PassiveDNS.constants.each do |const|
      if PassiveDNS.const_get(const).is_a?(Class) and PassiveDNS.const_get(const).superclass == PassiveDNS::PassiveDB
        class_map[PassiveDNS.const_get(const).config_section_name] = PassiveDNS.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

initialize



46
47
48
49
50
# File 'lib/passivedns/client.rb', line 46

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

#query(item, limit = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/passivedns/client.rb', line 52

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