Skip to content

Commit

Permalink
Look for NS DNS record first, then fall back to ANY
Browse files Browse the repository at this point in the history
  • Loading branch information
purcell committed Nov 6, 2012
1 parent 5a0dc30 commit f48d006
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions bin/postfix-policy-whois
Expand Up @@ -31,17 +31,20 @@ $LOG = Syslog.open($0, Syslog::LOG_PID | Syslog::LOG_PERROR, Syslog::LOG_MAIL)
require 'timeout' require 'timeout'
require 'resolv' require 'resolv'


def nameserver_for(domain) def resolve_to_name(domain, record_type)
Timeout::timeout(5) do begin
begin record = Resolv::DNS.new.getresource(domain, record_type)
record = Resolv::DNS.new.getresource(domain, Resolv::DNS::Resource::IN::NS) record.name.to_s if record.respond_to?(:name)
record.name.to_s if record.respond_to?(:name) rescue Resolv::ResolvError
rescue Resolv::ResolvError nil
nil
end
end end
end end


def nameserver_for(domain)
resolve_to_name(domain, Resolv::DNS::Resource::IN::NS) ||
resolve_to_name(domain, Resolv::DNS::Resource::IN::ANY)
end

def tld_and_nameserver(domain) def tld_and_nameserver(domain)
if ns = nameserver_for(domain) if ns = nameserver_for(domain)
[domain, ns] [domain, ns]
Expand Down

0 comments on commit f48d006

Please sign in to comment.