Skip to content

Instantly share code, notes, and snippets.

@shiv3
Created May 15, 2017 09:00
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 shiv3/219be24e182f1c2023b63e33d785b741 to your computer and use it in GitHub Desktop.
Save shiv3/219be24e182f1c2023b63e33d785b741 to your computer and use it in GitHub Desktop.
traceroute & ping script
#! /usr/bin/ruby
require "net/ping"
traceroute = `traceroute #{ARGV[0]}`
routepath = traceroute.split("\n")[1..-1].map do|s|
r = s.split(" ")[2].delete("()*")
r if r.length > 0
end
routepath.compact!
loop do
routepath.each_with_index do |path,i|
pinger = Net::Ping::External.new(path)
#print "\r" + " "*i
if pinger.ping?
print "\e[34m"
puts '○' + path
print "\e[0m"
else
print "\e[31m"
puts '×' + path
print "\e[0m"
end
end
sleep 1
print "\e[#{routepath.length}A"
STDOUT.flush
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment