Skip to content

Instantly share code, notes, and snippets.

@rtlong rtlong/expanded.rb
Created Jun 10, 2012

What would you like to do?
Ruby ping scan
finished = []
ips = []
range = 1..254
range.each do |i|
ip_address = "192.168.111.#{i}" do
`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
print "\r \r"
puts ips.sort do |a, b|
a.split(?.)[-1].to_i <=> b.split(?.)[-1].to_i
finished = []; ips = []; range = 1..254; range.each { |i| ip_address = "192.168.111.#{i}"; { `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 }

This comment has been minimized.

Copy link
Owner Author

rtlong commented Jun 10, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.