holamendi
5/30/2018 - 8:41 AM

Ruby DNS Check

Ruby DNS Check

require 'resolv'

class DnsCheck
  attr_reader :host
  def initialize(host)
    @host = host
  end

  def a
    @a ||= Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::A)
  end
  
  def cname 
    @cname ||= Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::CNAME)
  end

  def mx
    @mx ||= Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::MX)
  end

  def ns
    @ns ||= Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::NS)
  end
end