Created
June 28, 2017 02:43
-
-
Save bomatson/c438e41986c93b71ddefb77e94264b33 to your computer and use it in GitHub Desktop.
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 | |
# | |
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