Created
August 5, 2011 14:43
-
-
Save smith/1127675 to your computer and use it in GitHub Desktop.
Read domains from a CSV and get the IP of their MX.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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