Skip to content

Instantly share code, notes, and snippets.

@tombh
Created October 22, 2016 11:59
Show Gist options
  • Save tombh/fa670cdfb5bbbf9a00f3b4da6b813217 to your computer and use it in GitHub Desktop.
Save tombh/fa670cdfb5bbbf9a00f3b4da6b813217 to your computer and use it in GitHub Desktop.
#! 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