Skip to content

Instantly share code, notes, and snippets.

@showwin
Last active October 9, 2015 07: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 showwin/5e9fe93751c7aa251f5f to your computer and use it in GitHub Desktop.
Save showwin/5e9fe93751c7aa251f5f to your computer and use it in GitHub Desktop.
Speedtesting Tool for Japan
###### README ######
# Speedtesting Tool for Japan
#
# How to Use
# 1. Install pip
# `$ curl -kL https://raw.github.com/pypa/pip/master/contrib/get-pip.py | sudo python`
#
# 2. Install speedtest-cli (https://github.com/sivel/speedtest-cli)
# `$ pip install speedtest-cli`
#
# 3. Run This Script
# `$ ruby speedtest.rb`
#
# 4. Return Result
# `> Download Avg: 48.27 Mbit/s`
# `> Upload Avg: 44.79 Mbit/s`
###### README ######
REGIONS = %w(Shizuoka Tokyo Misawa Sakai)
RIDS = %w(6691 6424 6405 6477)
results = {}
REGIONS.each_with_index do |region, index|
puts "Speedtesting to #{REGIONS[index]} ..."
results[region] = `speedtest-cli --server #{RIDS[index]}`
end
download = 0
upload = 0
results.each do |_, result|
result =~ /Download:.+\/s/
down_str = $&
down_str =~ /[0-9]+\.[0-9]+/
download += $&.to_f
result =~ /Upload:.+\/s/
up_str = $&
up_str =~ /[0-9]+\.[0-9]+/
upload += $&.to_f
end
puts "\n"
puts "Date: #{Time.now.strftime('%Y/%m/%d %H:%M:%S')}"
puts "Download Avg: #{(download / 4.0).round(2)} Mbit/s"
puts "Upload Avg: #{(upload / 4.0).round(2)} Mbit/s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment