Monday, March 3, 2014

Simple DNS mx check

#!/usr/bin/env ruby
def check
 if ARGV[0] == nil
 abort 'plz input domain name'
 end
end

check

require 'resolv'
dns = Resolv::DNS.new
domain = ARGV[0]
dns.each_resource(domain, Resolv::DNS::Resource::IN::MX) do |mail_server|
 puts mail_server.exchange

end

#How to test
y-MacBook-Pro:rp young$ ruby mf.rb  
plz input domain name
y-MacBook-Pro:rp young$ ruby mf.rb yahoo.com
mta7.am0.yahoodns.net
mta5.am0.yahoodns.net
mta6.am0.yahoodns.net
y-MacBook-Pro:rp young$ ruby mf.rb nate.com
mx1.nate.com

No comments:

Post a Comment