Class: BetterCap::Discovery::Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/bettercap/discovery/thread.rb

Overview

Class responsible to actively discover targets on the network.

Instance Method Summary collapse

Constructor Details

#initialize(ctx) ⇒ Thread

Initialize the class using the ctx BetterCap::Context instance.



18
19
20
21
22
# File 'lib/bettercap/discovery/thread.rb', line 18

def initialize( ctx )
  @ctx     = ctx
  @running = false
  @thread  = nil
end

Instance Method Details

#startObject

Start the active network discovery thread.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bettercap/discovery/thread.rb', line 25

def start
  @running = true
  @thread  = ::Thread.new { worker }

  if @ctx.options.core.discovery?
    Logger.info "[#{'DISCOVERY'.green}] Targeting the whole subnet #{@ctx.iface.network.to_range} ..."
    # give some time to the discovery thread to spawn its workers,
    # this will prevent 'Too many open files' errors to delay host
    # discovery.
    sleep(1.5)
  end
end

#stopObject

Stop the active network discovery thread.



39
40
41
42
43
44
45
46
47
# File 'lib/bettercap/discovery/thread.rb', line 39

def stop
  @running = false
  if @thread != nil
    begin
      @thread.exit
    rescue
    end
  end
end