Skip to content

Instantly share code, notes, and snippets.

@bomatson
Created June 28, 2017 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bomatson/c438e41986c93b71ddefb77e94264b33 to your computer and use it in GitHub Desktop.
Save bomatson/c438e41986c93b71ddefb77e94264b33 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
require "csv"
require "timeout"
bad_ips = []
time = ARGV[1].to_i || 3
CSV.foreach(ARGV[0], headers: true) do |row|
return if row.nil?
ip = row["device_ip"]
return if ip.nil?
pid = Process.spawn("traceroute #{ip}")
begin
Timeout::timeout(time) {
Process.wait(pid)
}
rescue Timeout::Error
bad_ips << ip
Process.kill('TERM', pid)
end
end
puts "Here are the IPs that took longer than 30 seconds:"
puts bad_ips.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment