Протестировано с рубином 1.9.3 не плохо;
[slmn@uriel ~]$ time ruby ipmap.rb
"192.168.0.1"
"192.168.0.10"
real 0m2.393s
user 0m0.750s
sys 0m1.547s
Я прокомментировал области, если вы хотите выполнять свои операции в потоке;
require 'ipaddr'
ips = IPAddr.new("192.168.1.0/24").to_range
threads = ips.map do |ip|
Thread.new do
status = system("ping -q -W 1 -c 1 #{ip}",
[:err, :out] => "/dev/null")
# you can do your operations in thread like this
# if status
# # operations
# end
# optional
Thread.current[:result] = ip.to_s if status
end
end
threads.each {|t| t.join}
# if you don't do your operations in thread
threads.each do |t|
next unless t[:result]
# operations
#optional
puts t[:result]
end