Created
September 21, 2011 14:19
-
-
Save rogerbraun/1232149 to your computer and use it in GitHub Desktop.
How to ping a list of IP adresses to check if they are still in use
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
ips = File.readlines("ip_list").map(&:strip) | |
used_ips = [] | |
if File.exist?("used_ips") | |
used_ips = File.readlines("used_ips").map(&:strip) | |
end | |
ips -= used_ips | |
while ips.size > 0 do | |
puts "Starting new round..." | |
ips.each do |ip| | |
puts "Trying #{ip}" | |
res = `ping -c1 -t1 #{ip}` | |
if res["1 packets received"] then | |
puts "#{ip} answered!" | |
open("used_ips", "a") do |file| | |
file.puts ip | |
end | |
ips -= [ip] | |
end | |
end | |
sleep 60 * 10 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment