Class: Panopticon::WlanCapture
- Inherits:
-
Object
- Object
- Panopticon::WlanCapture
- Defined in:
- lib/panopticon/wlan_capture.rb
Constant Summary collapse
- CHAN =
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165]
- LIMIT_IDX =
CHAN.length
- DEFAULT_IFNAME =
"wlan0"- DEFAULT_INTERVAL =
1
Instance Attribute Summary collapse
-
#channel_walk ⇒ Object
readonly
Returns the value of attribute channel_walk.
-
#current_channel ⇒ Object
readonly
Returns the value of attribute current_channel.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#filesize ⇒ Object
readonly
Returns the value of attribute filesize.
-
#utilization ⇒ Object
readonly
Returns the value of attribute utilization.
-
#utilization_channel ⇒ Object
readonly
Returns the value of attribute utilization_channel.
Instance Method Summary collapse
-
#initialize(ifname = DEFAULT_IFNAME, channels = CHAN, interval = DEFAULT_INTERVAL) ⇒ WlanCapture
constructor
A new instance of WlanCapture.
- #modify_channels(channels) ⇒ Object
- #run_capture(fpath) ⇒ Object
- #stop_capture ⇒ Object
Constructor Details
#initialize(ifname = DEFAULT_IFNAME, channels = CHAN, interval = DEFAULT_INTERVAL) ⇒ WlanCapture
Returns a new instance of WlanCapture.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/panopticon/wlan_capture.rb', line 18 def initialize ifname=DEFAULT_IFNAME, channels=CHAN, interval = DEFAULT_INTERVAL @th_shark = nil @th_capture = nil @black_list = [] @ifname = ifname || DEFAULT_IFNAME @channels = channels || CHAN @interval = interval || DEFAULT_INTERVAL init_status() @wlan_utilization = Panopticon::WlanUtilization.new(@ifname) end |
Instance Attribute Details
#channel_walk ⇒ Object (readonly)
Returns the value of attribute channel_walk.
6 7 8 |
# File 'lib/panopticon/wlan_capture.rb', line 6 def channel_walk @channel_walk end |
#current_channel ⇒ Object (readonly)
Returns the value of attribute current_channel.
6 7 8 |
# File 'lib/panopticon/wlan_capture.rb', line 6 def current_channel @current_channel end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
6 7 8 |
# File 'lib/panopticon/wlan_capture.rb', line 6 def duration @duration end |
#filesize ⇒ Object (readonly)
Returns the value of attribute filesize.
6 7 8 |
# File 'lib/panopticon/wlan_capture.rb', line 6 def filesize @filesize end |
#utilization ⇒ Object (readonly)
Returns the value of attribute utilization.
6 7 8 |
# File 'lib/panopticon/wlan_capture.rb', line 6 def utilization @utilization end |
#utilization_channel ⇒ Object (readonly)
Returns the value of attribute utilization_channel.
6 7 8 |
# File 'lib/panopticon/wlan_capture.rb', line 6 def utilization_channel @utilization_channel end |
Instance Method Details
#modify_channels(channels) ⇒ Object
70 71 72 |
# File 'lib/panopticon/wlan_capture.rb', line 70 def modify_channels channels @channels = channels end |
#run_capture(fpath) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/panopticon/wlan_capture.rb', line 32 def run_capture fpath init_device() init_status() start_time = Time.now.to_i stdin, stdout, stderr, @th_tshark = *Open3.popen3( "tshark -i #{@ifname} -F pcapng -w #{fpath}") while @th_tshark.alive? sleep 1 # update status @duration = Time.now.to_i - start_time @filesize = File.size?(fpath) || 0 # do something here to run before channel transition ary = @wlan_utilization.current_data() @utilization_channel = ary[0] @utilization = ary[3] prev_channel = @current_channel @current_chanenl = move_channel(@current_channel, @channels) @channel_walk += 1 $log.debug("channel moved to #{@current_channel} from #{prev_channel} (dur=#{@duration}, size=#{@filesize}, walk=#{@channel_walk}, utilization=#{@utilization} uch=#{@utilization_channel})") end rescue => e $log.warn("run_capture detected unknown error (#{e})") end |
#stop_capture ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/panopticon/wlan_capture.rb', line 61 def stop_capture if @th_tshark == nil $log.err("tried to kill tshark, but it's not executed? (or already dead?)") return end Process.kill("INT", @th_tshark.pid) end |