Skip to content

Instantly share code, notes, and snippets.

@ross-nordstrom
Created October 5, 2014 17:14
Show Gist options
  • Save ross-nordstrom/c8f6583de4d1db3f87d0 to your computer and use it in GitHub Desktop.
Save ross-nordstrom/c8f6583de4d1db3f87d0 to your computer and use it in GitHub Desktop.
Get a breakdown of wifi protocol usage. Assumes wireless interface accessible at "wlan0".
#!/usr/bin/env ruby
require 'json'
wifi = `iwlist wlan0 scan`
pieces2ghz = wifi.split("Cell ")[1..-1]
data = pieces2ghz.map{ |x| [ (x.split('Protocol:')[1].split("\n")[0] rescue '[UNKNOWN]') ] }
protocols = data.reduce({}) do |protocols, x|
protocols[x[0]] = protocols[x[0]] ? protocols[x[0]] + 1 : 1
protocols
end
puts protocols.to_json.gsub(/"/, "'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment