To search for MX records you have to use the Resolv::DNS class : IP Address « Network « Ruby






To search for MX records you have to use the Resolv::DNS class

 
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

 








Related examples in the same category

1.resolv useful for converting between hostnames and IP addresses
2.Get all the addresses associated with a hostname
3.turn IP addresses into hostnames using the getname method