Class: BetterCap::Discovery::Agents::Base

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

Overview

Base class for BetterCap::Discovery::Agents.

Direct Known Subclasses

Arp, Udp

Instance Method Summary collapse

Constructor Details

#initialize(ctx, address = nil) ⇒ Base

Initialize the agent using the ctx BetterCap::Context instance. If address is not nil only that ip will be probed.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bettercap/discovery/agents/base.rb', line 22

def initialize( ctx, address = nil )
  @ctx       = ctx
  @ifconfig  = ctx.ifconfig
  @local_ip  = @ifconfig[:ip_saddr]
  @address   = address

  if @address.nil?
    net = ip = @ifconfig[:ip4_obj]
    # loop each ip in our subnet and push it to the queue
    while net.include?ip
      unless skip_address?(ip)
        @ctx.packets.push( get_probe(ip) )
      end
      ip = ip.succ
    end
  else
    if skip_address?(@address)
      Logger.debug "Skipping #{@address} ..."
    else
      Logger.debug "Probing #{@address} ..."
      @ctx.packets.push( get_probe(@address) )
    end
  end
end