Class: BetterCap::Sniffer
- Inherits:
-
Object
- Object
- BetterCap::Sniffer
- Includes:
- PacketFu
- Defined in:
- lib/bettercap/sniffer/sniffer.rb
Overview
network packet sniffing and dumping.
Constant Summary collapse
- @@ctx =
nil
- @@parsers =
nil
- @@pcap =
nil
- @@cap =
nil
Class Method Summary collapse
-
.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.
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.
28 29 30 31 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 60 61 |
# File 'lib/bettercap/sniffer/sniffer.rb', line 28 def self.start( ctx ) Thread.new { Logger.debug 'Starting sniffer ...' setup( ctx ) start = Time.now skipped = 0 processed = 0 self.stream.each do |raw_packet| break unless @@ctx.running begin parsed = PacketFu::Packet.parse(raw_packet) rescue Exception => e parsed = nil end if skip_packet?(parsed) skipped += 1 else processed += 1 append_packet raw_packet parse_packet parsed end end stop = Time.now delta = ( stop - start ) * 1000.0 total = skipped + processed Logger.info "[#{'SNIFFER'.green}] #{total} packets processed in #{delta} ms ( #{skipped} skipped packets, #{processed} processed packets )" } end |