aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/mauve_resolv.rb
blob: 6c97befb174f6e6469b530226fc7678240288d78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'resolv-replace'

#
#
#

module Mauve
  class MauveResolv
    class << self
      def get_ips_for(host)
        record_types = %w(A AAAA)
        ips = []

        %w(A AAAA).each do |type|
          begin
            Resolv::DNS.open do |dns|
              dns.getresources(host, Resolv::DNS::Resource::IN.const_get(type)).each do |a|
                 ips << a.address.to_s
              end
            end
          rescue Resolv::ResolvError, Resolv::ResolvTimeout => e
            logger.warn("#{host} could not be resolved because #{e.message}.")
          end
        end
        ips
      end

      def logger
        @logger ||= Log4r::Logger.new(self.to_s)
      end
    end
  end
end