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, from_exclusion_list, inherited, #initialize, load_by_names, load_custom, #match_port?

Constructor Details

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

Instance Method Details

#on_packet(pkt) ⇒ Object



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 24

def on_packet( pkt )
  return unless pkt.udp_dst == 161

  packet = Network::Protos::SNMP::Packet.parse( pkt.payload )

  return if 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 )
rescue
end