Last active
August 29, 2015 14:23
-
-
Save pchaigno/824a93489c827a18af3d to your computer and use it in GitHub Desktop.
Check MX records for domains in swot gem
This file contains hidden or 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
require 'helper' | |
require 'net/smtp' | |
require 'resolv' | |
def resolve_mx(domain) | |
mxs = Resolv::DNS.open do |dns| | |
ress = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) | |
ress.map { |r| r.exchange.to_s } | |
end | |
return mxs | |
end | |
def resolve_a(domain) | |
mxs = Resolv::DNS.open do |dns| | |
ress = dns.getresources(domain, Resolv::DNS::Resource::IN::A) | |
ress.map { |r| | |
r.address | |
} | |
end | |
return mxs | |
end | |
def check_domain(domain) | |
www_domain = "www.#{domain}" | |
mx_domain = "mx.#{domain}" | |
mail_domain = "mail.#{domain}" | |
return resolve_mx(domain).length > 0 || resolve_a(domain).length > 0 || resolve_a(www_domain).length > 0 || resolve_mx(mx_domain).length > 0 || resolve_mx(mail_domain).length > 0 | |
end | |
failed = 0 | |
tot = 0 | |
start = false | |
Swot.each_domain { |domain| | |
if domain.to_s | |
begin | |
if check_domain(domain.to_s) | |
puts "Seems okay: #{domain}" | |
else | |
puts "No record: #{domain}" | |
failed += 1 | |
end | |
rescue => e | |
puts "Error: #{domain}" | |
raise | |
end | |
tot += 1 | |
end | |
} | |
puts "Failed: #{failed}/#{tot}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment