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) ⇒ Base

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


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bettercap/discovery/agents/base.rb', line 20

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

  net = ip = @ifconfig[:ip4_obj]
  # loop each ip in our subnet and push it to the queue
  while net.include?ip
    # rescanning the gateway could cause an issue when the
    # gateway itself has multiple interfaces ( LAN, WAN ... )
    if ip != ctx.gateway and ip != @local_ip
      packet = get_probe(ip)
      @ctx.packets.push(packet)
    end

    ip = ip.succ
  end
end