Skip to content

mvenditto/DotNetSnmp

Repository files navigation

DotNetSnmp

Build codecov NuGet

SnmpDotNet is a NET 6 SNMP client built ontop of System.Formats.Asn1 BER serialization capabilities.

ℹ️ The library is in early development stage and subject to frequent api changes!

Try the NuGet Package

Goals:

  • support for SNMP V1, V2c and V3
  • modern C# implementation with a focus on memory efficiency
  • low level api + higher-level abstractions to ease usage in common use cases

A Sneak peek of the Dispatcher API

using DotNetSnmp.Client;
using DotNetSnmp.Common.Definitions;
using DotNetSnmp.Protocol.V1;
using DotNetSnmp.Transport;
using DotNetSnmp.Transport.Targets;
using System.Net;

var targetAddress = new IPEndPoint(
    IPAddress.Parse("127.0.0.1"), 161);

var dispatcher = new SnmpDispatcher();

var response = await dispatcher.SendPdu(
    new BasicUdpTransport(targetAddress),
    new CommunityTarget("public"), // dafaults to v1
    targetAddress,
    new GetRequestPdu()
    {
        VariableBindings = new(
            "1.3.6.1.2.1.1.1.0", // sysDescr
            "1.3.6.1.2.1.1.3.0"  // sysUptime
        )
    }
);

foreach(var varBind in response.VariableBindings)
{
    Console.WriteLine(varBind);
}

Output:

1.3.6.1.2.1.1.1.0 = String: SnmpTestAgentContainer
1.3.6.1.2.1.1.3.0 = Timeticks: (471603) 00:01:18:36.02