Sha256: 2017c223deb5288880763e20720a41e060516b1d15690a567931dc29a6448adf

Contents?: true

Size: 692 Bytes

Versions: 14

Compression:

Stored size: 692 Bytes

Contents

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

module Tuktuk

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

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
tuktuk-0.9.0 lib/tuktuk/dns.rb
tuktuk-0.8.0 lib/tuktuk/dns.rb
tuktuk-0.7.1 lib/tuktuk/dns.rb
tuktuk-0.7.0 lib/tuktuk/dns.rb
tuktuk-0.6.5 lib/tuktuk/dns.rb
tuktuk-0.6.4 lib/tuktuk/dns.rb
tuktuk-0.6.3 lib/tuktuk/dns.rb
tuktuk-0.6.2 lib/tuktuk/dns.rb
tuktuk-0.6.1 lib/tuktuk/dns.rb
tuktuk-0.6.0 lib/tuktuk/dns.rb
tuktuk-0.5.4 lib/tuktuk/dns.rb
tuktuk-0.5.3 lib/tuktuk/dns.rb
tuktuk-0.5.2 lib/tuktuk/dns.rb
tuktuk-0.5.1 lib/tuktuk/dns.rb