Skip to content

Instantly share code, notes, and snippets.

@vderyagin
Created August 23, 2012 12:34
Show Gist options
  • Save vderyagin/3436243 to your computer and use it in GitHub Desktop.
Save vderyagin/3436243 to your computer and use it in GitHub Desktop.
Test network by investigating connection to servers in different geographical locations.
#!/usr/bin/env ruby
=begin
Test network by investigating connection to servers in different geographical
locations.
Prints results to stdout.
Shells out to mtr(1) (http://www.bitwizard.nl/mtr/).
=end
MTR = '/usr/sbin/mtr'
PINGS_COUNT = String 100
SITES = %w(
109.te.ua meta.ua interfax.com.ua
lenta.ru lib.ru yandex.ru
kernel.org europa.eu google.com
)
separator = '=' * 80
mtr_version = IO.popen [MTR, '--version'] do |process|
process.read
end
out = STDOUT
out.puts Time.now
out.puts mtr_version
SITES.each do |site|
command = []
command << MTR
command << '--report'
command << '--report-cycles' << PINGS_COUNT
command << '--order' << 'LSRDNBAW'
command << site
out.puts separator
out.puts "#{site}:"
out.puts
IO.popen command do |process|
out.puts process.read
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment