aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/mauve_resolv.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-03-21 19:10:11 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-03-21 19:10:11 +0000
commit495780ac5299b26009bea86319f44301bd301db1 (patch)
treea9a2bbd4f3e799c8a26f84b05d84bee6fecfdcbc /lib/mauve/mauve_resolv.rb
parent56cb1ef45e0cae7336fcbe83994addcae61f429b (diff)
Possible performance improvements.
Diffstat (limited to 'lib/mauve/mauve_resolv.rb')
-rw-r--r--lib/mauve/mauve_resolv.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/mauve/mauve_resolv.rb b/lib/mauve/mauve_resolv.rb
index c6460e3..a9c7526 100644
--- a/lib/mauve/mauve_resolv.rb
+++ b/lib/mauve/mauve_resolv.rb
@@ -15,23 +15,26 @@ module Mauve
# @return [Array] Array of IP addresses, as Strings.
#
def get_ips_for(host)
- record_types = %w(A AAAA)
+ pp host
ips = []
-
- %w(A AAAA).each do |type|
- begin
- Resolv::DNS.open do |dns|
- dns.getresources(host, Resolv::DNS::Resource::IN.const_get(type)).each do |a|
- ips << a.address.to_s
- end
+ @count ||= 0
+ Resolv::DNS.open do |dns|
+ %w(A AAAA).each do |type|
+ @count += 1
+ begin
+ ips += dns.getresources(host, Resolv::DNS::Resource::IN.const_get(type)).collect{|a| a.address.to_s}
+ rescue Resolv::ResolvError, Resolv::ResolvTimeout => e
+ logger.warn("#{host} could not be resolved because #{e.message}.")
end
- rescue Resolv::ResolvError, Resolv::ResolvTimeout => e
- logger.warn("#{host} could not be resolved because #{e.message}.")
end
end
ips
end
+ def count
+ @count ||= 0
+ end
+
# @return [Log4r::Logger]
def logger
@logger ||= Log4r::Logger.new(self.to_s)