Class: Waps_mac

Inherits:
Object
  • Object
show all
Defined in:
lib/waps_mac.rb

Instance Method Summary collapse

Constructor Details

#initializeWaps_mac

Returns a new instance of Waps_mac.



5
6
# File 'lib/waps_mac.rb', line 5

def initialize
end

Instance Method Details

#parse(raw_input) ⇒ Object



13
14
15
16
17
# File 'lib/waps_mac.rb', line 13

def parse(raw_input)
	cells = raw_input.split("\n")[1..-1]

	cells.map { |cell|  parse_cell(cell)}
end

#parse_cell(cell) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/waps_mac.rb', line 25

def parse_cell(cell)
	raw_data = cell.split(" ")
	result = { 
		address: raw_data[1],
		channel: raw_data[3],
		signal_level: raw_data[2],
		encryption_key: pencryption_key(raw_data[6]),
		ssid: raw_data[0]
	}
end

#pencryption_key(data) ⇒ Object

Parse Values from the raw data. All methods below



39
40
41
# File 'lib/waps_mac.rb', line 39

def pencryption_key(data)
	data == "NONE" ? "off" : "On"
end

#run_commandObject



19
20
21
22
# File 'lib/waps_mac.rb', line 19

def run_command
	output,error,status = Open3.capture3("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s")
	return output == "" ? {error: error} : {output: output}
end

#scanObject



8
9
10
11
# File 'lib/waps_mac.rb', line 8

def scan
	raw_input = run_command
	@output = (raw_input.keys.include? :error) ? raw_input : parse(raw_input[:output])
end