Created
October 22, 2016 11:59
-
-
Save tombh/fa670cdfb5bbbf9a00f3b4da6b813217 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
#! env ruby | |
loop do | |
begin | |
ping = `ping -n -c 1 -W 3 google.in 2>&1` | |
rescue | |
puts "Failed ping" | |
sleep 1 | |
next | |
end | |
time_regex = ping.match(/time=(.*) ms/) | |
if time_regex.nil? | |
host_regex = ping.match(/Name or service not known/) | |
if host_regex.nil? | |
puts "Timed out" | |
else | |
puts "No Internet" | |
sleep 1 | |
end | |
next | |
end | |
time = time_regex.captures.first.to_f | |
tone = 500000 / time | |
puts "#{time}ms: #{tone}Hz" | |
`altonegen -t 1 -f #{tone} 2>&1 > /dev/null` | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment