Ruby 查询域名的 MX 记录

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

require 'resolv'

Resolv::DNS.open do |dns|
  mail_servers = dns.getresources("google.com", Resolv::DNS::Resource::IN::MX)
  mail_servers.each do |server|
    puts "#{server.exchange.to_s} - #{server.preference}"
  end
end