Dear Sir(s),
I'm looking for a quick to scan the local network (/24). I choose to use 'net-ping' gem, since I'm working under Ruby 1.9 and 'ping' is not available by default.
I use the 'external' ping because it's way faster but still very slow. It takes like 2 minutes to 'ping' 254 addresses with a 2 hosts 'up'. So I decided to make it a bit faster by using threads. Since I have no prior experience with Threads, I've read a couple of articles about ruby threads and here is the code that I came up with:
···
------------------------
require 'net/ping'
network = '192.168.1.'
list = []
host_up = []
host_down = []
x = 1
while x < 255
ip = network + x.to_s
list.push(ip)
x += 1
end
list.each { |x|
t = Thread.new {
pt = Net::Ping::External.new(x)
if pt.ping
host_up.push(x)
else
host_down.push(x)
end
}
}
puts host_up
-------------------------
First thing, do I use Threads the right way?
Second, Trying to find out whats going on from 'lsof -i', I counted 155 simultaneous connections but not more. It should be 254 in theory?
Third, do you think that is there any faster way in scanning weather a host is up or not? I understand that this is a more general question, but tools like 'ettercap' scan a /24 network in less than 10 seconds on the same machine same network, which makes me thing that I'm doing something wrong. I'm not experienced programmer, neither experienced with computer networks at that level, like Alor and Naga (author's of ettercap) but then again, why the difference is so big? :-/
Thanks for your time.
Panagiotis Atmatzidis
-----------------------------
Pharmacy Student at VFU, Brno
mailing lists: ml@convalesco.org
personal mail: atma@convalesco.org
personal info: http://about.me/atmosx
The wise man said: "Never argue with an idiot, he brings you down to his level and beat you with experience."