Skip to content

Instantly share code, notes, and snippets.

@Thamrius
Created February 4, 2019 04:12
Show Gist options
  • Save Thamrius/3f75c76cbe50c8b2ed705266032071e4 to your computer and use it in GitHub Desktop.
Save Thamrius/3f75c76cbe50c8b2ed705266032071e4 to your computer and use it in GitHub Desktop.
ruby ping-sweep
#!/usr/bin/env ruby
finished = []
ips = []
range = 1..254
range.each do |i|
ip_address = "10.11.1.#{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_by! {|ip| ip.split('.').map{|octet| octet.to_i}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment