Class: BetterCap::Parsers::SNMP

Inherits:
Base
  • Object
show all
Defined in:
lib/bettercap/sniffer/parsers/snmp.rb

Overview

SNMP community string parser.

Instance Method Summary collapse

Methods inherited from Base

available, from_cmdline, inherited, #initialize, load_by_names, load_custom

Constructor Details

This class inherits a constructor from BetterCap::Parsers::Base

Instance Method Details

#on_packet(pkt) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bettercap/sniffer/parsers/snmp.rb', line 23

def on_packet( pkt )
  begin
    if pkt.udp_dst == 161

      packet = Network::Protos::SNMP::Packet.parse( pkt.payload )
      unless packet.nil?
      	if packet.snmp_version_number.to_i == 0
      	  snmp_version = 'v1'
      	else
      	  snmp_version = 'n/a'
      	end

        msg = "[#{'Version:'.green} #{snmp_version}] [#{'Community:'.green} #{packet.snmp_community_string.map { |x| x.chr }.join.yellow}]"

        StreamLogger.log_raw( pkt, 'SNMP', msg )
      end
    end
  rescue; end
end