Querying DNS

DNS에 Recursive query가 가능한지 체크하는 도구입니다.

#!/usr/local/bin/ruby -w

# == Synopsis
# Test whether a given DNS supports DNS query. If the result is
# "Yes", then you should modify DNS server setting ASAP.
#
# == Usage
# recursive_dns.rb [dns server ip]
#  - ex> ./recursive_dns.rb 123.456.789.012
#
# == Author
# h4q0

require "resolv"
require "rdoc/usage"

if ARGV.length != 1
    RDoc::usage
end

name = "123.456.789.012"
nameserver = ARGV[0]

puts "Querying nameserver:#{nameserver} for ip:#{name}"

config = Resolv::DNS::Config.new
msg = Resolv::DNS::Message.new
msg.add_question(name, Resolv::DNS::Resource::IN::A)
requester = Resolv::DNS::Requester::ConnectedUDP.new(nameserver)
q = Queue.new
sender = requester.sender(msg, name, q, nameserver)
sender.send

reply = reply_name = nil

timeout(1, RuntimeError.new("Timeout")) { reply, reply_name = q.pop }

requester.close

puts "Recursive query turned on? #{reply.ra == 1 ? "Yes": "No"}"

Similar Posts:

Post a Comment

Your email is never published nor shared.