Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#! 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