Created
February 4, 2019 04:12
-
-
Save Thamrius/3f75c76cbe50c8b2ed705266032071e4 to your computer and use it in GitHub Desktop.
ruby ping-sweep
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
#!/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