Created
June 10, 2012 23:05
-
-
Save rtlong/2907619 to your computer and use it in GitHub Desktop.
Ruby ping scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
finished = [] | |
ips = [] | |
range = 1..254 | |
range.each do |i| | |
ip_address = "192.168.111.#{i}" | |
Thread.new do | |
`ping -q -c1 -W1 #{ip_address}`.split(/\n+/)[2].split(/,\s*/)[1].to_i > 0 and ips << ip_address | |
finished << i | |
end | |
end | |
until finished.count == range.count | |
print "\r%#{(finished.count/range.count.to_f * 100).round}" | |
sleep 0.1 | |
end | |
print "\r \r" | |
puts ips.sort do |a, b| | |
a.split(?.)[-1].to_i <=> b.split(?.)[-1].to_i | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
finished = []; ips = []; range = 1..254; range.each { |i| ip_address = "192.168.111.#{i}"; Thread.new { `ping -q -c1 -W1 #{ip_address}`.split(/\n+/)[2].split(/,\s*/)[1].to_i > 0 and ips << ip_address; finished << i } }; until finished.count == range.count; print "\r%#{(finished.count/range.count.to_f * 100).round}"; sleep 0.1; end; print "\r \r"; puts ips.sort { |a, b| a.split(?.)[-1].to_i <=> b.split(?.)[-1].to_i } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was tested only on MRI Ruby 1.9.3-p194. You may need to tweak the timeout or counts, depending on the nature and quality of the network you're testing.