Permalink
Browse files

Look for NS DNS record first, then fall back to ANY

  • Loading branch information...
purcell committed Nov 6, 2012
1 parent 5a0dc30 commit f48d006090318413500824de4e9c92f333892f33
Showing with 11 additions and 8 deletions.
  1. +11 −8 bin/postfix-policy-whois
View
@@ -31,17 +31,20 @@ $LOG = Syslog.open($0, Syslog::LOG_PID | Syslog::LOG_PERROR, Syslog::LOG_MAIL)
require 'timeout'
require 'resolv'
-def nameserver_for(domain)
- Timeout::timeout(5) do
- begin
- record = Resolv::DNS.new.getresource(domain, Resolv::DNS::Resource::IN::NS)
- record.name.to_s if record.respond_to?(:name)
- rescue Resolv::ResolvError
- nil
- end
+def resolve_to_name(domain, record_type)
+ begin
+ record = Resolv::DNS.new.getresource(domain, record_type)
+ record.name.to_s if record.respond_to?(:name)
+ rescue Resolv::ResolvError
+ nil
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)
if ns = nameserver_for(domain)
[domain, ns]

0 comments on commit f48d006

Please sign in to comment.