How to parse SNMP traps in C#?

B-K Hariprasad 1 Reputation point
2022-05-10T10:10:39.327+00:00

Hi All,
We have a C# console application built on .Net core. We have requirement to parse SNMP trap in C#. My question is is there any method/class available in to parse below sample SNMP trap?

Sample SNMP trap:

2020-08-04 04:56:45

04:56:44 2020/08/04 PDU INFO:
notificationtype TRAP
version 0
receivedfrom UDP: [192.168.100.100]:38977->[192.168.100.20]:162
errorstatus 0
messageid 0
community admin
transactionid 1056
errorindex 0
requestid 0
VARBINDS:
DISMAN-EVENT-MIB::sysUpTimeInstance type=67 value=Timeticks: (57947996) 6 days, 16:57:59.96
SNMPv2-MIB::snmpTrapOID.0 type=6 value=OID: IF-MIB::linkUp
IF-MIB::ifIndex.19 type=2 value=INTEGER: 19
IF-MIB::ifAdminStatus.19 type=2 value=INTEGER: 1
IF-MIB::ifOperStatus.19 type=2 value=INTEGER: 1
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 type=64 value=IpAddress: 192.168.100.100
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 type=4 value=STRING: "admin"
SNMPv2-MIB::snmpTrapEnterprise.0 type=6 value=OID: SNMPv2-SMI::enterprises.25506.11.1.219


Can anyone please let us know the best way to get this done!!
Any help is appreciated. Thank you in advance!!

Best Regards,
Hari

Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Lex Li (Microsoft) 6,037 Reputation points Microsoft Employee
    2024-11-04T22:15:03.3133333+00:00

    You can build upon C# SNMP Library (#SNMP) to monitor incoming SNMP TRAP/INFORM messages, as it has a TRAP listener sample,

    https://github.com/lextudio/sharpsnmplib-samples/tree/master/Samples/CSharpCore/snmptrapd

    However, if you want to format OIDs and data types properly, that requires MIB parsing functionality and is only available with #SNMP Pro.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.