Class: Evinrude::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/evinrude/resolver.rb

Instance Method Summary collapse

Constructor Details

#initializeResolver

Returns a new instance of Resolver.



6
7
8
9
10
# File 'lib/evinrude/resolver.rb', line 6

def initialize
  @config = Config.new
  p @config
  @resolver = Async::DNS::Resolver.new(Async::DNS::System.standard_connections(@config.nameservers))
end

Instance Method Details

#getaddresses(name) ⇒ Object



12
13
14
# File 'lib/evinrude/resolver.rb', line 12

def getaddresses(name)
  (getresources(name, Resolv::DNS::Resource::IN::AAAA) + getresources(name, Resolv::DNS::Resource::IN::A)).map(&:address).map(&:to_s)
end

#getresources(name, rtype) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/evinrude/resolver.rb', line 16

def getresources(name, rtype)
  search_candidates(name).each do |fqdn|
    response = @resolver.query(fqdn, rtype)

    if response.rcode != Resolv::DNS::RCode::NoError
      next
    end

    return response.answer.map { |rr| rr[2] }
  end

  []
end