Class: Waps_linux
- Inherits:
-
Object
- Object
- Waps_linux
- Defined in:
- lib/waps_linux.rb
Instance Method Summary collapse
-
#initialize(interface_name) ⇒ Waps_linux
constructor
A new instance of Waps_linux.
- #paddress(data) ⇒ Object
- #parse(raw_input) ⇒ Object
- #parse_cell(cell) ⇒ Object
- #pchannel(data) ⇒ Object
- #pencryption_key(data) ⇒ Object
- #pfrequency(data) ⇒ Object
- #pquality(data) ⇒ Object
- #psignal_level(data) ⇒ Object
- #pssid(data) ⇒ Object
- #run_command ⇒ Object
- #scan ⇒ Object
Constructor Details
#initialize(interface_name) ⇒ Waps_linux
Returns a new instance of Waps_linux.
5 6 7 8 |
# File 'lib/waps_linux.rb', line 5 def initialize(interface_name) @interface_name = interface_name @output = [] end |
Instance Method Details
#paddress(data) ⇒ Object
44 45 46 |
# File 'lib/waps_linux.rb', line 44 def paddress(data) data.split("Address:")[-1].delete(" ") end |
#parse(raw_input) ⇒ Object
15 16 17 18 19 |
# 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) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
48 49 50 |
# File 'lib/waps_linux.rb', line 48 def pchannel(data) data.split(":")[-1] end |
#pencryption_key(data) ⇒ Object
64 65 66 |
# File 'lib/waps_linux.rb', line 64 def pencryption_key(data) data.split(":")[-1] end |
#pfrequency(data) ⇒ Object
52 53 54 |
# File 'lib/waps_linux.rb', line 52 def pfrequency(data) data.split(":")[-1].split(" ")[0] end |
#pquality(data) ⇒ Object
56 57 58 |
# File 'lib/waps_linux.rb', line 56 def pquality(data) data.split(" ")[0].split("=")[-1] end |
#psignal_level(data) ⇒ Object
60 61 62 |
# File 'lib/waps_linux.rb', line 60 def psignal_level(data) data.split(" ")[2].split("=")[-1] + " dBm" end |
#pssid(data) ⇒ Object
68 69 70 |
# File 'lib/waps_linux.rb', line 68 def pssid(data) data.split('"').count == 1 ? "" : data.split('"')[-1] end |
#run_command ⇒ Object
21 22 23 24 |
# 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 ⇒ Object
10 11 12 13 |
# 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 |