lib/globetrotter.rb in globetrotter-0.0.10 vs lib/globetrotter.rb in globetrotter-0.0.11
- old
+ new
@@ -29,12 +29,16 @@
"for #{query}, #{@concurrency} at a time, "\
"with a timeout of #{@timeout_seconds} second(s)."
$stderr.puts message
EM.run do
- result_ips = Set.new
- result_ips.merge(@file.set) if @file
+ if @file
+ result_ips = @file.set
+ size_before = result_ips.size
+ else
+ result_ips = Set.new
+ end
ok = 0
nok = 0
EM::Iterator.new(@ns_ips, @concurrency).each(
proc do |ns_ip, iter|
resolver = RubyDNS::Resolver.new(
@@ -43,11 +47,11 @@
)
resolver.query(query) do |response|
case response
when RubyDNS::Message
response.answer.each do |answer|
- address = answer[2].address.to_s
+ address = IPAddr.new(answer[2].address.to_s)
result_ips.add(address)
end
ok += 1
iter.next
when RubyDNS::ResolutionFailure
@@ -57,16 +61,18 @@
end
end,
proc do
EM.stop
if @file
+ size_after = result_ips.size
+ new_results = size_after - size_before
@file.set = result_ips
@file.write
else
result_ips.each { |ip| puts ip }
end
$stderr.puts "#{ok} succeeded, #{nok} failed (#{ok + nok} total)"
- $stderr.puts "Results written to #{@file}" if @file
+ $stderr.puts "Wrote #{new_results} new unique result(s) to #{@file}" if @file
end
)
end
end