Created
May 15, 2017 09:00
-
-
Save shiv3/219be24e182f1c2023b63e33d785b741 to your computer and use it in GitHub Desktop.
traceroute & ping script
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/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