Skip to content

Instantly share code, notes, and snippets.

@rogerbraun
Created September 21, 2011 14:19
Show Gist options
  • Save rogerbraun/1232149 to your computer and use it in GitHub Desktop.
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
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