Class: Waps
- Inherits:
-
Object
- Object
- Waps
- Defined in:
- lib/waps.rb
Instance Method Summary collapse
- #get(find) ⇒ Object
-
#initialize(interface_name) ⇒ Waps
constructor
A new instance of Waps.
- #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
Returns a new instance of Waps.
3 4 5 6 |
# File 'lib/waps.rb', line 3 def initialize(interface_name) @interface_name = interface_name @output = [] end |
Instance Method Details
#get(find) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/waps.rb', line 74 def get(find) result = [] if @output[0].keys.include? find.to_sym result = @output.map { |cell| cell[find.to_sym] } end result end |
#paddress(data) ⇒ Object
41 42 43 |
# File 'lib/waps.rb', line 41 def paddress(data) data.split("Address:")[-1].delete(" ") end |
#parse(raw_input) ⇒ Object
13 14 15 16 17 |
# File 'lib/waps.rb', line 13 def parse(raw_input) cells = raw_input.split("Cell")[1..-1] cells.map { |cell| parse_cell(cell)} end |
#parse_cell(cell) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/waps.rb', line 24 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
45 46 47 |
# File 'lib/waps.rb', line 45 def pchannel(data) data.split(":")[-1] end |
#pencryption_key(data) ⇒ Object
61 62 63 |
# File 'lib/waps.rb', line 61 def pencryption_key(data) data.split(":")[-1] end |
#pfrequency(data) ⇒ Object
49 50 51 |
# File 'lib/waps.rb', line 49 def pfrequency(data) data.split(":")[-1].split(" ")[0] end |
#pquality(data) ⇒ Object
53 54 55 |
# File 'lib/waps.rb', line 53 def pquality(data) data.split(" ")[0].split("=")[-1] end |
#psignal_level(data) ⇒ Object
57 58 59 |
# File 'lib/waps.rb', line 57 def psignal_level(data) data.split(" ")[2].split("=")[-1] + " dBm" end |
#pssid(data) ⇒ Object
65 66 67 |
# File 'lib/waps.rb', line 65 def pssid(data) data.split('"').count == 1 ? "" : data.split('"')[-1] end |
#run_command ⇒ Object
19 20 21 |
# File 'lib/waps.rb', line 19 def run_command `sudo iwlist #{@interface_name} scan` end |
#scan ⇒ Object
8 9 10 11 |
# File 'lib/waps.rb', line 8 def scan raw_input = run_command @output = parse(raw_input) end |