Class: BetterCap::Sniffer

Inherits:
Object
  • Object
show all
Includes:
PacketFu
Defined in:
lib/bettercap/sniffer/sniffer.rb

Overview

Class responsible of loading BetterCap::Parsers instances and performing network packet sniffing and dumping.

Constant Summary collapse

@@ctx =
nil
@@parsers =
nil
@@pcap =
nil
@@cap =
nil

Class Method Summary collapse

Class Method Details

.start(ctx) ⇒ Object

Start a new thread that will sniff packets from the network and pass each one of them to the BetterCap::Parsers instances loaded inside the ctx BetterCap::Context instance.


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bettercap/sniffer/sniffer.rb', line 30

def self.start( ctx )
  Thread.new do
    Logger.debug 'Starting sniffer ...'

    setup( ctx )

    self.stream.each do |p|
      break unless @@ctx.running
      begin
        parsed = Packet.parse p
      rescue Exception => e
        parsed = nil
        Logger.debug e.message
      end

      if not parsed.nil? and parsed.is_ip? and !skip_packet?(parsed)
        append_packet p
        parse_packet parsed
      end
    end
  end
end