Skip to content

Instantly share code, notes, and snippets.

@smith
Created August 5, 2011 14:43
Show Gist options
  • Save smith/1127675 to your computer and use it in GitHub Desktop.
Save smith/1127675 to your computer and use it in GitHub Desktop.
Read domains from a CSV and get the IP of their MX.
# Read domains from a CSV and get the IP of their MX.
require 'resolv'
require 'csv'
Resolv::DNS.open do |dns|
CSV.foreach('/Users/smith/Desktop/domains.csv') do |row|
domain = row[1]
next if domain == 'domain' # heading
mxs = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
if mxs.length == 0
puts ""
else
begin
puts dns.getaddress(mxs[0].exchange)
rescue Resolv::ResolvError => e
puts ""
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment