class Waps_linux
Public Class Methods
new(interface_name)
click to toggle source
# File lib/waps_linux.rb, line 5 def initialize(interface_name) @interface_name = interface_name @output = [] end
Public Instance Methods
paddress(data)
click to toggle source
Parse Values from the raw data. All methods below
# File lib/waps_linux.rb, line 44 def paddress(data) data.split("Address:")[-1].delete(" ") end
parse(raw_input)
click to toggle source
# File lib/waps_linux.rb, line 15 def parse(raw_input) cells = raw_input.split("Cell")[1..-1] cells.map { |cell| parse_cell(cell)} end
parse_cell(cell)
click to toggle source
# File lib/waps_linux.rb, line 27 def parse_cell(cell) raw_data = cell.split("\n") result = { address: paddress(raw_data[0]), channel: pchannel(raw_data[1]), frequency: pfrequency(raw_data[2]), quality: pquality(raw_data[3]), signal_level: psignal_level(raw_data[3]), encryption_key: pencryption_key(raw_data[4]), ssid: pssid(raw_data[5]) } end
pchannel(data)
click to toggle source
# File lib/waps_linux.rb, line 48 def pchannel(data) data.split(":")[-1] end
pencryption_key(data)
click to toggle source
# File lib/waps_linux.rb, line 64 def pencryption_key(data) data.split(":")[-1] end
pfrequency(data)
click to toggle source
# File lib/waps_linux.rb, line 52 def pfrequency(data) data.split(":")[-1].split(" ")[0] end
pquality(data)
click to toggle source
# File lib/waps_linux.rb, line 56 def pquality(data) data.split(" ")[0].split("=")[-1] end
psignal_level(data)
click to toggle source
# File lib/waps_linux.rb, line 60 def psignal_level(data) data.split(" ")[2].split("=")[-1] + " dBm" end
pssid(data)
click to toggle source
# File lib/waps_linux.rb, line 68 def pssid(data) data.split('"').count == 1 ? "" : data.split('"')[-1] end
run_command()
click to toggle source
# File lib/waps_linux.rb, line 21 def run_command output,error,status = Open3.capture3("sudo iwlist #{@interface_name} scan") return output == "" ? {error: error} : {output: output} end
scan()
click to toggle source
# File lib/waps_linux.rb, line 10 def scan raw_input = run_command @output = (raw_input.keys.include? :error) ? raw_input : parse(raw_input[:output]) end