Created
October 5, 2014 17:34
-
-
Save ross-nordstrom/6c9ffe084e4e88a4e90b to your computer and use it in GitHub Desktop.
Get a breakdown of WiFi utilization by relative signal strength. Assumes wireless interface accessible at "wlan0".
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'json' | |
wifi = `iwlist wlan0 scan` | |
pieces2ghz = wifi.split("Cell ")[1..-1].select{|x| x.include?('Signal level=')} | |
data = pieces2ghz.map{ |x| [(x.split('Signal level=')[1].split('/')[0] rescue '0').to_i ]} | |
signals = { :'Very Weak' => 0, :Poor => 0, :Fair => 0, :Strong => 0 } | |
signals = data.reduce(signals) do |signals, x| | |
if(x[0] > 70) | |
type = :Strong | |
elsif(x[0] > 50) | |
type = :Fair | |
elsif(x[0] > 20) | |
type = :Poor | |
else | |
type = :'Very Weak' | |
end | |
signals[type] += 1 | |
signals | |
end | |
puts signals.to_json.gsub(/"/, "'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment