Sha256: 09deed105fcd19ce55f3acea29eaba9f1376060545807b7f81dc9fb2d9eb4f49

Contents?: true

Size: 672 Bytes

Versions: 6

Compression:

Stored size: 672 Bytes

Contents

begin
  require 'resolv'
rescue
  require 'net/dns/resolve'
end

module DNS

  class << self

    def get_mx(host)
      if defined?(Resolv::DNS)
        get_using_resolve(host)
      else
        get_using_net_dns(host)
      end
    end

    def get_using_resolve(host)
      Resolv::DNS.open do |dns|
        if res = dns.getresources(host, Resolv::DNS::Resource::IN::MX)
          sort_mx(res)
        end
      end
    end

    def get_using_net_dns(host)
      if res = Net::DNS::Resolver.new.mx(host)
        sort_mx(res)
      end
    end

    def sort_mx(res)
      res.sort {|x,y| x.preference <=> y.preference}.map { |rr| rr.exchange.to_s }
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tuktuk-0.5.0 lib/tuktuk/dns.rb
tuktuk-0.4.6 lib/tuktuk/dns.rb
tuktuk-0.4.5 lib/tuktuk/dns.rb
tuktuk-0.4.4 lib/tuktuk/dns.rb
tuktuk-0.3.1 lib/tuktuk/dns.rb
tuktuk-0.3.0 lib/tuktuk/dns.rb